Results 1 to 2 of 2

Thread: Table Macro

  1. #1
    New Lounger
    Join Date
    Jul 2013
    Thanked 0 Times in 0 Posts

    Table Macro

    I'm a total novice regarding Word Macros and VBA. I have a large number of tables in client deliverable documents that need to be reformatted into a standard style, so I'm attempting to build a Word 2010 macro that will find all tables in the document and:

    1. Select the first row and apply a "Table Heading" style to all text
    2. Select all subsequent rows and apply a "Table Body" style to all text
    3. Select the whole table and apply a custom defined Table Style to it

    Could anyone point me to any websites that are good resources for macro code? I've tried Googling, but not much luck when it comes to tables. Alternatively, if you have some sample code you could share, I'd appreciate it.

    Thanks much in advance.

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Melbourne, Victoria, Australia
    Thanked 295 Times in 267 Posts
    The code is pretty straightforward but I have added a bit of other stuff for no apparent reason
    Sub FormatAllTables()
    Dim objTable as Table
        For Each objTable In ActiveDocument.Tables
          With objTable
            .Style = "Table Grid"   'table style
            .Range.Style = "Table Body"  'paragraph style
            .Rows.HeadingFormat = False
            .ApplyStyleHeadingRows = True
            .Rows(1).HeadingFormat = True  'uses table style heading row format instead of another paragraph style
            .PreferredWidthType = wdPreferredWidthPercent
            .PreferredWidth = 100
          End With
        Next objTable
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts