merge table cells

User avatar
stuck
Panoramic Lounger
Posts: 8225
Joined: 25 Jan 2010, 09:09
Location: retirement

merge table cells

Post by stuck »

This page:
https://msdn.microsoft.com/en-us/librar ... 14%29.aspx
says this code:

Code: Select all

ActiveDocument.Tables(1).Cell(Row:=1, Column:=1).Merge MergeTo:=.Cell(Row:=1, Column:=2) 
will merge two cells but when I try it, it bombs at 'MergeTo:=.Cell' saying method or data member not found.
:scratch:

Ken
PS yes, I am using Word 2010

User avatar
stuck
Panoramic Lounger
Posts: 8225
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: merge table cells

Post by stuck »

OK, found an alternative construct (thank you Paul aka macropod):

Code: Select all

With Selection.Tables(1)
Set Rng = .Cell(1, 3).Range
Rng.End = .Cell(1, numCols).Range.End
Rng.Cells.Merge
End With
and that does work.

Ken

User avatar
HansV
Administrator
Posts: 78789
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: merge table cells

Post by HansV »

Glad you found an alternative solution. You omitted the With ... End With construction from the sample code in the Microsoft article.
Best wishes,
Hans