Hi,
I have written following script to find and format nested tables.
Dim c As Integer
Dim r As Integer
Dim nt As Integer
Dim TotalTables As Integer
Dim TotalNestedTables As Integer
Dim numColums As Integer
Dim numRows As Integer
TotalTables = ActiveDocument.Tables.Count
For t = 1 To TotalTables
Set objTable = ActiveDocument.Tables(t)
numColums = objTable.Columns.Count
numRows = objTable.Rows.Count
For c = 1 To numColums
For r = 1 To numRows
TotalNestedTables = objTable.Cell(r, c).Tables.Count
If TotalNestedTables > 0 Then
For nt = 1 To objTable.Cell(r, c).Tables.Count
objTableNested.AutoFitBehavior wdAutoFitContent
Next nt
End If
Next r
Next c
Next t
End Sub
the script fails at: TotalNestedTables = objTable.Cell(r, c).Tables.Count
and produces Run-time error 5941: The requested member of the collection does not exist.
I can understand the error because the all tables don’t contain any nested table.
My question is how to avoid this error?