Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Macro for table width in percentage

    Hi,
    I have a huge financial file for formatting and this has lot of tables and different column width through out the file for eg.

    3 column width table consists of :
    70 % + 15% + 15% respectively as table width (I need the width in percentage only and not in points or cm or mm)
    4 column width:
    55% + 15% + 15% + 15%
    5 column width:
    40% + 15% + 15% + 15% +15%
    6 column width:
    40% + 12% +12% +12% +12% +12% and so on and I need upto around 9 colcumn width where the 1st column least size can be 28% and cannot go less than that but the next column width can vary.

    The width need to be measured in percentage because when uploaded on webpage as HTML file the table should expand accordingly


    Please help!!

    Thank you in advance

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,894
    Thanks
    0
    Thanked 188 Times in 172 Posts
    You could try something like:
    Code:
    Sub TableColumnFormat()
    Dim Tbl As Table, i As Long, Wdth As Single
    For Each Tbl In ActiveDocument.Tables
      With Tbl
        .PreferredWidthType = wdPreferredWidthPercent
        .PreferredWidth = 100
        Wdth = 100 / (.Columns.Count + 3)
        For i = 2 To .Columns.Count
          With .Columns(i)
            .PreferredWidthType = wdPreferredWidthPercent
            .PreferredWidth = Wdth
          End With
        Next
        With .Columns(1)
          .PreferredWidthType = wdPreferredWidthPercent
          .PreferredWidth = Wdth * 4
        End With
      End With
    Next
    End Sub
    With the above code, all columns are dynamically resized. The results are slightly different to what you asked for, but the approach taken makes for more consistent re-scaling as the column count increases. FWIW, using the above code the first column in a 3-column table is 2/3 the total width and, even in a 9-column table it only reduces to 1/3 the total width.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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
  •