Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Standardizing Table Width

    Using Word 97 in Windows 95/98.

    I need to convert a lot of tables to have the same overall width. They are all 2 columns, but the columns are not all the same width. The first columns give a term which vary a good bit in length. The second column will be shorter when the first column is longer. Right now the second columns are all too long, going past the page margins (they are output from a conversion from HTML-based help).

    In essense, the following steps show what I want to happen (If you have a better way of accomplishing the same goal, feel free.):

    1. For every two column nonbordered table in the document.
    2. Find the width of the first column.
    3. Find the width of the second column.
    4. Add the widths together.
    5. Subtract the sum from 390 pt. (for example 100+400=500; 390-500=-110 [table too wide])
    6. If the result is negative (this will be true when the original table is wider than 390 pt), subtract the difference to the width of the second column.
    7. If the result is positive (this will be true when the original table is narrower than 390 pt), add the difference to the width of the second column.
    8. Go to the next table...until the end of the document.

    Thanks for your help!!
    Troy
    P.S. This Saturday I start Visual Basic 6.0 class. Hopefully I'll be able to start doing some of this for myself and helping others soon.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Standardizing Table Width

    Hi Troy,

    The following is a pretty literal transcription of your outlined steps (big credit to Big Al for the function to test for borders):

    <pre>Public Sub ResetTableWidths()
    'Gary Frieder Woody's Lounge VB/VBA Forum June 2001
    Dim aTable As Table
    Dim sngCol1W As Single
    Dim sngCol2W As Single
    Dim sngTblW As Single
    Dim sngDiffW As Single

    For Each aTable In ActiveDocument.Tables
    If aTable.Columns.Count = 2 And bIsBorderless(aTable) Then
    sngCol1W = aTable.Columns(1).Width
    sngCol2W = aTable.Columns(2).Width
    sngTblW = sngCol1W + sngCol2W
    sngDiffW = 390 - sngTblW
    If sngDiffW < 0 Then 'negative number, so add it:
    aTable.Columns(2).Width = sngCol2W + sngDiffW
    Else
    aTable.Columns(2).Width = sngCol2W + sngDiffW
    End If
    End If
    Next aTable
    End Sub
    '========================
    Public Function bIsBorderless(CurTable As Table) As Boolean
    'Borrowed from Big Al:
    Dim aBorder As Border
    For Each aBorder In CurTable.Borders
    If aBorder.LineStyle <> wdLineStyleNone Then
    bIsBorderless = False
    Exit Function
    End If
    Next aBorder
    bIsBorderless = True
    End Function
    </pre>


    Good luck with the VB course!
    (You might find though that an Office VBA course will be useful as well, for doing stuff like this.)

    Gary

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Standardizing Table Width- Amended

    Because you're either adding a negative number, or adding a positive number, there's no need for the If..Then..Else structure:

    <pre>Public Sub ResetTableWidths()
    'Gary Frieder Woody's Lounge VB/VBA Forum June 2001
    Dim aTable As Table
    Dim sngCol1W As Single
    Dim sngCol2W As Single
    Dim sngTblW As Single
    Dim sngDiffW As Single

    For Each aTable In ActiveDocument.Tables
    If aTable.Columns.Count = 2 And bIsBorderless(aTable) Then
    sngCol1W = aTable.Columns(1).Width
    sngCol2W = aTable.Columns(2).Width
    sngTblW = sngCol1W + sngCol2W
    sngDiffW = 390 - sngTblW
    aTable.Columns(2).Width = sngCol2W + sngDiffW
    End If
    Next 'aTable
    End Sub
    '========================
    Public Function bIsBorderless(CurTable As Table) As Boolean
    'Borrowed from Big Al:
    Dim aBorder As Border
    For Each aBorder In CurTable.Borders
    If aBorder.LineStyle <> wdLineStyleNone Then
    bIsBorderless = False
    Exit Function
    End If
    Next aBorder
    bIsBorderless = True
    End Function
    </pre>


  4. #4
    JustCallMeAl
    Guest

    Re: Standardizing Table Width- Amended

    I did that? Wow!

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Standardizing Table Width- Amended

    Got the idea from <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Cat=&Board=vb&Number=43603&page=&v iew=&sb=&o=&vc=1#Post43603>here</A>. <img src=/S/yep.gif border=0 alt=yep width=15 height=15>

  6. #6
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Standardizing Table Width

    This worked great. Thanks!!

    You mentioned an Office VBA class. What do you mean by this and how can I find them?

    Thanks!!
    Troy

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Standardizing Table Width

    Hi Troy,

    Glad that worked!

    As far as Office/VBA, I have heard of classroom courses being available but I'm afraid I don't have details - most likely you need to be in a major city to find these.

    There are excellent course materials for self-study available from AppDev - have a look <A target="_blank" HREF=http://www.appdev.com/topics/product.asp?ID=9>here</A> - there's also some free downloadable intro material there as well. I did the CD-ROM version of their course about a year ago, and found it useful.

    Good luck!

    Gary

Posting Permissions

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