如何访问嵌套在另一个表中的范围内的表? [英] How to access a table within a range nested in another table?

查看:68
本文介绍了如何访问嵌套在另一个表中的范围内的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了访问某个范围内的单个表(例如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

这篇关于如何访问嵌套在另一个表中的范围内的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆