Reply
 
Thread Tools Display Modes
  #1   Report Post  
Andy Entrekin Andy Entrekin is offline
Junior Member
 
Posts: 2
Default Macro to merge cells?

I need help with a macro to merge a specified set of cells in a table in a Word 2007 document. My goal is to use code to avoid having to tell hundreds of users which cells to select and merge in a large table, since asking them to do that would inevitably lead to problems. What I've determined so far is that I can't record such a macro, because I can't select the table cells once the macro recorder is active. Once the cells are merged, I want to enter and format text, also using the macro (since it will always say exactly the same thing, to meet regulatory requirements).

As an example, I'd like a macro that will:
Merge the cells from row 32, column 18 through row 38, column 25
Enter the text "Approved Document" in the merged cell and format it as bold and red.

Any and all help will be greatly appreciated.

Last edited by Andy Entrekin : May 10th 12 at 08:10 PM
  #2   Report Post  
kipster kipster is offline
Junior Member
 
Posts: 1
Default

Quote:
Originally Posted by Andy Entrekin View Post
I need help with a macro to merge a specified set of cells in a table in a Word 2007 document. My goal is to use code to avoid having to tell hundreds of users which cells to select and merge in a large table, since asking them to do that would inevitably lead to problems. What I've determined so far is that I can't record such a macro, because I can't select the table cells once the macro recorder is active. Once the cells are merged, I want to enter and format text, also using the macro (since it will always say exactly the same thing, to meet regulatory requirements).

As an example, I'd like a macro that will:
Merge the cells from row 32, column 18 through row 38, column 25
Enter the text "Approved Document" in the merged cell and format it as bold and red.

Any and all help will be greatly appreciated.
Code:
Sub Macro1()

    Dim myCells As Range
    With ActiveDocument
        Set myCells = .Range(Start:=.Tables(1).Cell(32, 18).Range.Start, _
            End:=.Tables(1).Cell(38, 25).Range.End)
        myCells.Select
    End With
    Selection.Cells.Merge
    With Selection.Font
        .Bold = True
        .Color = wdColorRed
    End With
    Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.TypeText Text:="Approved Document"
    
End Sub
Does that help?

Last edited by kipster : May 11th 12 at 08:52 AM
  #3   Report Post  
Andy Entrekin Andy Entrekin is offline
Junior Member
 
Posts: 2
Thumbs up

That did it - thanks!!!
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to merge two table cells? David Newmarch Microsoft Word Help 6 May 11th 10 01:32 PM
macro to merge two table cells? David Newmarch Microsoft Word Help 0 May 11th 10 10:12 AM
macro to detect merged table cells? Tony Logan Tables 3 August 18th 06 11:14 PM
Doug's Attachment macro-handling empty cells aeacsharp Mailmerge 3 February 20th 06 05:15 PM
Select specific cells in table via macro Bill Sturdevant Microsoft Word Help 1 July 27th 05 03:01 PM


All times are GMT +1. The time now is 06:30 AM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"