Results 1 to 4 of 4

Thread: Macro help!

  1. #1
    New Lounger
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro help!

    Hey guys, I've literally been trying to make a macro for weeks to update a string of hundreds of documents, but after much effort and frustration, I have had no luck.


    So these documents have tables that expand the entire width of the document. I'm trying to reduce the width of the tables in every document, while keeping the columns proportional to one another. There are around 12-15 tables in each document and I refuse to do it manually! I'm trying to reduce the width to match the numbering in the document, which is indented.

    Can anyone point me in the right direction? All I have found online is the following macro to adjust the column sizes of a table:

    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


    And I found it on this forum

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,549
    Thanks
    3
    Thanked 149 Times in 142 Posts
    I would assume that the column widths should all reduce proportionally in your document. So I would just resize the overall table rather than address each column individually
    Code:
    Sub TableFormatter()
      Dim oTbl As Table
      For Each oTbl In Selection.Tables
        With oTbl
          .Rows.AllowBreakAcrossPages = False
          .Rows(1).HeadingFormat = True
          .PreferredWidthType = wdPreferredWidthPoints
          .PreferredWidth = CentimetersToPoints(10)
        End With
      Next
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,979
    Thanks
    0
    Thanked 208 Times in 189 Posts
    I suggest you shouldn't be using 'Selection', as that requires you to select the tables you want to process. Rather, use 'ActiveDocument'.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,549
    Thanks
    3
    Thanked 149 Times in 142 Posts
    I should have mentioned that too but I assumed that perhaps the OP didn't want to change a section of the document such as tables in the front matter.
    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
  •