检查工作表中是否存在任何ListObjects
如果我正在循环查看表单,并且想要testing给定表单中是否存在任何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条件块仍然运行。
Worksheet.ListObjects
是一个集合,所以它不是Nothing
。 就像Paul Bica评论的那样,你想要统计集合中有多less个对象。 尝试这个:
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