Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to change widths of tables

    I am using Vista and Word 2007.

    I have a landscape document (well a few) with lots of tables. However, the widths of the columns are all over the place and I need to make the columns to be:

    1.19 / 2 / 1.19 / 2 / 2.62

    Also I need that the “Allow rows to break across pages” not be selected, because I want the information to go to the next page if necessary. Also some of the tables have this selected and some do not.

    I do not need the macro to go to the next table because there is text in between the tables and I would run the macro when I encounter a table.

    I recorded the column widths but when I played the macro the table becomes very small and the column widths are not fixed.

    Can somebody help me create a macro that does this? Thank you in advance.
    Last edited by vgarrim; 2011-02-06 at 11:37.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Hi vgarrim,

    You could use a macro like the following:
    Code:
    Sub TableFormatter()
    Dim oTbl As Table, i As Integer
    For Each oTbl In Selection.Tables
      With oTbl
        .Rows.AllowBreakAcrossPages = False
        .Rows(1).HeadingFormat = True
        For i = 1 To .Columns.Count
          If i = 1 Then .Columns(i).Width = InchesToPoints(1.19)
          If i = 2 Then .Columns(i).Width = InchesToPoints(2#)
          If i = 3 Then .Columns(i).Width = InchesToPoints(1.19)
          If i = 4 Then .Columns(i).Width = InchesToPoints(2#)
          If i = 5 Then .Columns(i).Width = InchesToPoints(2.62)
        Next
      End With
    Next
    End Sub
    If you select multiple tables, it will reformat each of them. Intervening text is unaffected. Tables with more or less columns are also reformatted - any extra columns are ignored. If a table spans more than one page, the first row is repeated as a Heading on each page (delete/comment out that line if you don't want it).

    Note: As coded, the macro won't work on tables with mixed cell widths in a column and/or merged cells.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you. Thank you. Thank you.

Posting Permissions

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