ayltonasc
07-16-2013, 08:24 AM
Hi guys, I'm trying to do a macro that applies format from the third collumn of a table to the last one, I did a macro that works for tables without merged cells, but I'm getting an error with table that contains merged cells.
I checked the word vba help and I founded an explation how to workaround this, but I didn't understand the help, the help stays:
- a runtime error will occur if the table is not uniform. For exemple: the table doesn't have the same number of lines in each collum, it is, it contains merged cells
The word vba help explains that a workaround for this is to firstly select the cells of a collumn, using the SelectColumn method.
I don't know how to do this, please, any one can help me with it?
the code I have that works just for table with no merged cells:
Sub ApplyCenterParagraphFormatFromThirdColumnToLastOne()
Dim c As Column
'findout the index number of the current table
CurrentTable = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count
'findout the columns quantity of the current table
Qtycolumns = Selection.Tables(1).Columns.Count
For i = 3 To Qtycolumns
ActiveDocument.Tables(TabelaAtual).Columns(i).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next i
End Sub
I checked the word vba help and I founded an explation how to workaround this, but I didn't understand the help, the help stays:
- a runtime error will occur if the table is not uniform. For exemple: the table doesn't have the same number of lines in each collum, it is, it contains merged cells
The word vba help explains that a workaround for this is to firstly select the cells of a collumn, using the SelectColumn method.
I don't know how to do this, please, any one can help me with it?
the code I have that works just for table with no merged cells:
Sub ApplyCenterParagraphFormatFromThirdColumnToLastOne()
Dim c As Column
'findout the index number of the current table
CurrentTable = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count
'findout the columns quantity of the current table
Qtycolumns = Selection.Tables(1).Columns.Count
For i = 3 To Qtycolumns
ActiveDocument.Tables(TabelaAtual).Columns(i).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next i
End Sub