Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2012, 04:16 AM
tinfanide tinfanide is offline Set range for merged Word table cells? Windows 7 64bit Set range for merged Word table cells? Office 2010 32bit
Expert
Set range for merged Word table cells?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Set range for merged Word table cells?

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
Please see the comments.


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)
But error...
Reply With Quote
  #2  
Old 02-06-2012, 05:57 AM
macropod's Avatar
macropod macropod is offline Set range for merged Word table cells? Windows 7 64bit Set range for merged Word table cells? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Set range for merged Word table cells? Word VBA: add textboxs in table cells? tinfanide Word VBA 12 02-09-2012 12:05 AM
Set range for merged Word table cells? Sum Formula in the range with Numeric and NonNumeric data cells Spanec Excel 2 01-12-2012 09:15 AM
Count range cells eliminating merge cells danbenedek Excel 0 06-15-2010 12:40 AM
Set range for merged Word table cells? Cut and paste a range of cells and preserve formatting 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft