我在Excel工作簿中有多个工作表,每个工作表都有一个表。我想选择一个对象中的所有工作表,以便我可以通过逐个选择set
对象中的表来迭代它们。
我该怎么做?
答案 0 :(得分:1)
这应该让你开始:
Dim ws As Worksheet
Dim tbl As ListObject
For Each ws In ThisWorkbook.Worksheets
For Each tbl In ws.ListObjects
Debug.Print ws.Name, tbl.Name, tbl.Range.Address
Next tbl
Next ws
修改:因为您似乎使用Tables
来谈论简单的Ranges
,所以这是一个面向Range
的替代方案:
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Debug.Print ws.Name, Range("A1").CurrentRegion.Address
Next ws
答案 1 :(得分:1)
Sub LoopThroughAllTablesinWorkbook()
Dim tbl As ListObject
Dim sht As Worksheet
For Each sht In ThisWorkbook.Worksheets
For Each tbl In sht.ListObjects
'Your code here...
Next tbl
Next sht
End Sub