如果我循环浏览我的工作表并想测试给定工作表中是否存在任何ListObjects,我该怎么做?我试过这个:
Dim daysoftheweek As Worksheet
For Each daysoftheweek In Sheets
If Not daysoftheweek.ListObjects Is Nothing Then
'Do Something Here - Only If The Sheet Contains A List Object
End If
Next
但即使表单不包含ListObject,IF条件块仍然会运行。
答案 0 :(得分:2)
Worksheet.ListObjects
是一个集合,因此它不是Nothing
。就像保罗比卡评论的那样,你想要计算集合中有多少个对象。试试这个:
Dim daysoftheweek As Worksheet
For Each daysoftheweek In Sheets
If daysoftheweek.ListObjects.Count > 0 Then
'Do Something Here - Only If The Sheet Contains A List Object
End If
Next