如何访问嵌套在另一个表中的范围内的表?

编程入门 行业动态 更新时间:2024-10-11 21:29:34
本文介绍了如何访问嵌套在另一个表中的范围内的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为了访问某个范围内的单个表(例如rngOuter),我使用了: tblOuter = rngOuter.Tables [1]; 在将嵌套表放在该外部范围表的某个范围内(例如rngInner)后,我发现: tblInner = rngInner.Tables [1]; 不工作. rngInner.Tables [1]引用tblOuter,而不是其内部的表. 实际上,rngInner的Tables集合只有一个元素,那就是tblOuter.为了访问tblInner,我必须到达tblOuter.Range.Tables [1].

In order to access the single table within a range (say, rngOuter) I used: tblOuter = rngOuter.Tables[1]; After I placed a nested table within a range (say, rngInner) within that outer range's table, I found that: tblInner = rngInner.Tables[1]; did not work. rngInner.Tables[1] references tblOuter, rather than the table within itself. In fact, Tables collection of rngInner has only one element, and that is tblOuter. In order to access tblInner, I have to get at tblOuter.Range.Tables[1].

有人知道我犯错了吗?就是这样吗?

Does anyone know if I am making a mistake, or that's the way it is?

推荐答案

AFAIK就是这样",但是您可以使用Cell.Tables而不是Cell.Range.Tables查找包含表的单元格.例如在当前选择中查找包含您可以使用的表格的单元格

AFAIK "that's the way it is", but you can look for cells that contain tables by using Cell.Tables rather than Cell.Range.Tables. e.g. to look for cells in the current selection that contain tables you could use

Sub listInnerTables() Dim c As Cell Dim r As Range Dim t As Table Dim tcount As Long Set r = Selection.Range If r.Tables.Count > 0 Then tcount = 0 For Each t In r.Tables tcount = tcount + 1 For Each c In t.Range.Cells If c.Range.InRange(r) Then If c.Tables.Count > 0 Then Debug.Print "Table: " & CStr(tcount) & _ vbTab & " Row: " & CStr(c.RowIndex) & _ vbTab & " Col: " & CStr(c.ColumnIndex) & _ vbTab & " Table count: " & CStr(c.Tables.Count) End If End If Next Next End If Set r = Nothing End Sub

更多推荐

如何访问嵌套在另一个表中的范围内的表?

本文发布于:2023-11-07 19:25:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   范围内

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!