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.
This should work:
Debug.Print Active.Document.Tables.Count
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With