• Width of a table (Word 2000)

    Author
    Topic
    #398332

    Hi

    In Visual Basic for Word, how do you determine (and set) the width of a table? Do you have to do it column by column?

    Thanks
    Dale

    Viewing 2 reply threads
    Author
    Replies
    • #760667

      The Table object as a whole has properties PreferredWidthType and PreferredWidth.

      PreferredWidthType can be set to values wdPreferredWidthAuto, wdPreferredWidthPercent and wdPreferredWidthPoints.
      If you set it to wdPreferredWidthPercent, you can set PreferredWidth to a number (percentage) between 1 and 100, and if you set it to wdPreferredWidthPoints, you can set it to a number of points (1 inch = 72 points).

      With ActiveDocument.Tables(1)
      .PreferredWidthType = wdPreferredWidthPercent
      .PreferredWidth = 50
      End With

      You can also set the AutoFitBehavior property. Its values are wdAutoFitContent (try to make the columns wide enough for their contents), wdAutoFitWindow (make the table fit between the page margins) and wdAutoFitFixed.

      • #760680

        Thanks Hans and Andrew

        I haven’t expressed myself clearly enough.

        I want to (a) determine the width of table #1, and then ( make table #2 the same width. From what you’ve told me, I understand how I can do (, but how do you do (a)?

        Thanks
        Dale

        • #760702

          If both tables have the same number of columns, it is probably easiest to loop through the columns and make each column in table #2 the same width as the corresponding column in table #1, as you originally suggested.

        • #760703

          If both tables have the same number of columns, it is probably easiest to loop through the columns and make each column in table #2 the same width as the corresponding column in table #1, as you originally suggested.

        • #760859

          You can calculate the sum of the widths of all columnsin Table(1) and again for Table(2). If both values are not the same, you can adjust the width of one or more columns in Table(2).

        • #760860

          You can calculate the sum of the widths of all columnsin Table(1) and again for Table(2). If both values are not the same, you can adjust the width of one or more columns in Table(2).

      • #760681

        Thanks Hans and Andrew

        I haven’t expressed myself clearly enough.

        I want to (a) determine the width of table #1, and then ( make table #2 the same width. From what you’ve told me, I understand how I can do (, but how do you do (a)?

        Thanks
        Dale

    • #760670

      You can do it either way depending on whether the table width is controlled (either by % page width or by a fixed size)

      Turn on your macro recorder and do it in Word and then look at the code to see what gets recorded.

    • #760671

      You can do it either way depending on whether the table width is controlled (either by % page width or by a fixed size)

      Turn on your macro recorder and do it in Word and then look at the code to see what gets recorded.

    Viewing 2 reply threads
    Reply To: Width of a table (Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: