Questions

Word tables in VBA - how to merge certain cells

Tags:
+
0 Votes
Locked

Word tables in VBA - how to merge certain cells

ariadne
Hi all,

I'm creating a macro which is basically formatting data in Word. There is a table which needs some cells merged.
The first two merges work fine: it's when the macro hits the third it doesn't recognize the selections anymore. Has anyone ever encountered this before? An excerpt of the macro can be seen here:

' Merging the first line
ActiveDocument.Tables(Nummer).Rows(1).Select
Selection.Cells.Merge

' Merging revenues and the rest
ActiveDocument.Tables(Nummer).Cell(1, 1).Select
Selection.SetRange _
Start:=Selection.Tables(Nummer).Cell(3, 1).Range.Start, _
End:=Selection.Tables(Nummer).Cell(3, 4).Range.End
Selection.Cells.Merge

Selection.Tables(1).Select
ActiveDocument.Tables(Nummer).Cell(1, 1).Range.Select
Selection.SetRange _
Start:=Selection.Tables(Nummer).Cell(5, 1).Range.Start, _
End:=Selection.Tables(Nummer).Cell(5, 2).Range.End
Selection.Cells.Merge

The first two merges look fine: the other one doesn't. Any help is very much appreciated!
Thanks,
Ariadne
  • +
    0 Votes
    ariadne

    Just thought to share this piece of information should it help out.
    After looking through the code a kazilion time it occured to me that the original table had the cells already merged. So therefore the code couldn't merge cells which were already merged.

    Solved it by using this piece of code:

    Selection.Cells.Split NumRows:=1, NumColumns:=5, MergeBeforeSplit:=False

  • +
    0 Votes
    ariadne

    Just thought to share this piece of information should it help out.
    After looking through the code a kazilion time it occured to me that the original table had the cells already merged. So therefore the code couldn't merge cells which were already merged.

    Solved it by using this piece of code:

    Selection.Cells.Split NumRows:=1, NumColumns:=5, MergeBeforeSplit:=False