I have a Word document consisting of multiple (25) tables.
I need to (programmatically) format the width of the second column of each table to "fit to contents" and have tried the following (as well as several other attempts) -
Sub ColumnFormat()
'
TblCount = ActiveDocument.Tables.Count
For x = 1 To TblCount
ActiveDocument.Tables(x).Select
With Selection
.Tables(x).AutoFitBehavior (wdAutoFitContent)
End With
Next x
End Sub
OK, I know this will format the entire table but I've got to start somewhere...
This runs fine for the first table then successfully selects the second table at which point the following error message appears -
"Run-time error '5941':
The requested member of the collection does not exist",
with the line ".Tables(x).AutoFitBehavior (wdAutoFitContent)" highlighted.
Is it even possible to format a single column in vba?
I've tried recording a macro, but the "Table/AutoFit/AutoFitContents" menu item isn't available.
I need to (programmatically) format the width of the second column of each table to "fit to contents" and have tried the following (as well as several other attempts) -
Sub ColumnFormat()
'
TblCount = ActiveDocument.Tables.Count
For x = 1 To TblCount
ActiveDocument.Tables(x).Select
With Selection
.Tables(x).AutoFitBehavior (wdAutoFitContent)
End With
Next x
End Sub
OK, I know this will format the entire table but I've got to start somewhere...
This runs fine for the first table then successfully selects the second table at which point the following error message appears -
"Run-time error '5941':
The requested member of the collection does not exist",
with the line ".Tables(x).AutoFitBehavior (wdAutoFitContent)" highlighted.
Is it even possible to format a single column in vba?
I've tried recording a macro, but the "Table/AutoFit/AutoFitContents" menu item isn't available.