![]() |
#1
|
|||
|
|||
![]() Code:
Dim oWord As Word.Application Set oWord = New Word.Application Dim oDoc As Word.Document Set oDoc = oWord.Documents.Add oWord.Visible = True oDoc.Activate With oWord Dim Table1 As Word.Table Set Table1 = oDoc.Tables.Add(Range:=oDoc.ActiveWindow.Selection.Range, _ NumRows:=6, _ NumColumns:=3, _ DefaultTableBehavior:=wdWord8TableBehavior) With Table1 .Rows.WrapAroundText = True .Borders(wdBorderTop).LineStyle = wdLineStyleSingle .Borders(wdBorderRight).LineStyle = wdLineStyleSingle .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle .Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle .Borders(wdBorderVertical).LineStyle = wdLineStyleSingle .Rows(1).Cells.Merge .Rows(2).Cells.Merge .Rows(3).Cells.Merge .Cell(4, 2).Select With oDoc.ActiveWindow.Selection .MoveDown Unit:=wdLine, Count:=2, Extend:=wdExtend .Cells.Merge ''' Here, how can I reference to this merged cells? ''' I mean ''' Dim rng As Range ''' Set rng = ??? .Text = "Merged Column Cells" End With End With End With I have tried Code:
Dim rng As Range Set rng = ActiveDocument.Range(Start:=ActiveDocument.Tables(1).Cell(4,2).Range.Start,End:=ActiveDocument.Tables(1).Cell(6,2).Range.End) |
#2
|
||||
|
||||
![]()
Hi tinfanide,
When developing automation code, it's often simpler to develop the target application's code in that application, then copy it to the automating application. In Word, when you merge cells horizontally, only the left-most cell remains. Similarly, when you merge cells vertically, only the top-most cell remains. You can no longer address any of the other cells in the merged range. Try something based on the following Word macro: Code:
Sub Demo() Dim Rng As Word.Range, oDoc As Word.Document Set oDoc = ActiveDocument With oDoc.Tables(1) Set Rng = .Cell(4, 2).Range Rng.End = .Cell(6, 2).Range.End Rng.Cells.Merge Rng.Text = "Merged Column Cells" End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
tinfanide | Word VBA | 12 | 02-09-2012 12:05 AM |
![]() |
Spanec | Excel | 2 | 01-12-2012 09:15 AM |
Count range cells eliminating merge cells | danbenedek | Excel | 0 | 06-15-2010 12:40 AM |
![]() |
StarWeaver | Excel | 1 | 03-02-2010 01:41 PM |
How do I reference a merged cell in a multi column & row table in MS Word ('03')? | jihanemo | Word Tables | 0 | 03-18-2009 08:33 AM |