Consulting

Results 1 to 3 of 3

Thread: Solved: error applying format in some table collumns because it contains merged cells

  1. #1

    Solved: error applying format in some table collumns because it contains merged cells

    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:

    [VBA]
    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

    [/VBA]

  2. #2
    oops, it had an error, that's the right code, corrected but still doens't work for merged cells.

    [VBA]
    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(CurrentTable).Columns(i).Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Next i

    End Sub

    [/VBA][/QUOTE]

  3. #3
    solved, I got it, that's the final code:

    [VBA]
    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(CurrentTable).Columns(i).Select
    ActiveDocument.Tables(CurrentTable).Cell(1, i).Select
    Selection.SelectColumn
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Next i

    End Sub
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •