Reputation: 1549
I have a Word document with many tables.
I need to count the number of tables.
I have tried the following VBA
Dim T as Table
Dim i as Integer
Dim Tables as Integer
For Each T In wdDoc.Tables
i = i + 1
Exit For
Next
Tables = i
End sub
However this comes back with
"Run-time error '424': Object required".
I also found on the internet the code
Tables = wdDoc.Tables.Count
Creating a macro with this code doesn't seem to do anything.
Upvotes: 4
Views: 15655
Reputation: 61
Using Word 2016, the recommended answer was still running into an error. I tried a slightly revised version combining the answer & comments above. Having a period between "Active" and "Document" caused the macro to fail. I swapped in Message Box for Debug.Print, and this worked:
Sub CountTables()
'
' CountTables Macro
'
'
MsgBox ActiveDocument.Tables.Count
End Sub
Upvotes: 3