Loop Through Tables in Word and then perform a Merge
Hi (Reopened)
This is a follow on from my previous thread. I need to create a macro which will loop through tables in word (or be able to specify which table I want to update) and then perform the row by row column merge as provided to me over the weekend.
Sub MergeTableRowByRow()
Dim Rng As Range, TblRw As Row
With ActiveDocument.Tables(1)
For Each TblRw In .Rows
Set Rng = TblRw.Cells(2).Range
Rng.End = TblRw.Cells(3).Range.End
Rng.Cells.Merge
Next
End With
End Sub
My word document has a number of tables which each have a different numbers of columns/rows and it's only one particular table in my document that I need to run the above merge for.
Update:
I can hardcode the table in the ActiveDocument.Tables(x) but some users have not created the document in the same format so one users Table 9 could be another users Table 12. I will therefore need to be perform a loop through the tables until I see the one what I need on the screen and once located perform the above merge.
Thanks in advance.
Last edited by KD999; 02-20-2012 at 04:52 AM.
Reason: Doesn't work
|