PDA

View Full Version : Run-time error '5992' Cannot access individual columns in this collection because...



scubadunc
08-12-2015, 09:18 PM
I have a macro that selects only tables in a document that have more than 6 columns, sets the table width to the width of the page and right aligns the final column. The code below worked fine yesterday and correctly formatted any > 6 column tables. I ran it again today on the same document and I'm now getting this error:

Run-time error '5992' Cannot access individual columns in this collection because the table has mixed cell widths

Firstly why would it work one day and not the next and secondly how can I fix my code??

Sub RightAlignLastColumn()
Dim oTable As Table
Dim oCol As Column
Dim oCell As Cell
For Each oTable In ActiveDocument.Tables
For Each oCol In oTable.Columns
If oCol.Index > 6 Then
oTable.AutoFitBehavior (wdAutoFitWindow)
For Each oCell In oCol.Cells
oCell.Range.ParagraphFormat.Alignment _
= wdAlignParagraphRight
Next
End If
Next
Next
End Sub

Kind regards