• Portrait / Landscape Macro Problem

    • This topic has 3 replies, 2 voices, and was last updated 13 years ago.
    Author
    Topic
    #483130

    I have a macro as below that with one click converts a portrait page to landscape and adjusts the header and footer. The header and footer both have three column tables that hold images and fields. It has worked very nicely for over ten years! The macro is stored in a global template in WordStartup and is run from a number of templates.

    Now I have created a new template, again with three column tables and the macro runs except it whilst the ruler shows the landscape page width when the cursor is in the body of the document, the page width when in the header has not adjusted.

    Screenshot 1 shows the new template with the cursor in the body.

    30820-landscape001

    Screenshot 2 shows the old template with the cursor in the body. Ruler shows same width.

    30821-landscape002

    Screenshot 3 shows the new template with the cursor in the body.

    30822-landscape003

    Screenshot 4 shows the old template with the cursor in the header. Ruler shows a different width.

    30823-landscape004

    I have attached the macro as a text file. The last macro in the file runs the others in turn.

    Can anyone see what I am missing please? I am not a VB expert. Most of my macros are recordings or hacks of recordings.

    Viewing 2 reply threads
    Author
    Replies
    • #1331789

      … and the answer is “make sure the tables don’t have a defined width, just set the cells to have a width and let the macro adjust that”.

      Doh!

    • #1331791

      My head hurts looking at your code so I’m not going to rework it.

      I suspect the problem is that the header is linked to the previous section (which has a different page layout). If you break that link then you should see the expected margins. Your code toggles this setting – better to explicitly set it to False.

      The resizing of the table can sometimes be done simply by setting the width to 100%. In your case, you might want to fix a couple of column’s widths and allow the other two to resize according to the available space.

      The following code assumes you have passed in a value for the Section Number iSect

      Code:
        Dim aTable As Table, lngWidth as Long
        With ActiveDocument.Sections(iSect)
          lngWidth = .Range.PageSetup.PageWidth – .Range.PageSetup.LeftMargin – .Range.PageSetup.RightMargin
          For Each aTable In .Headers(wdHeaderFooterPrimary).Range.Tables
            If aTable.Columns.Count = 3 Then
              aTable.Columns(3).Width = CentimetersToPoints(6)
              aTable.Columns(2).Width = CentimetersToPoints(4)
              aTable.Columns(1).Width = lngWidth – aTable.Columns(2).Width – aTable.Columns(3).Width
            End If 
          Next aTable
        End With
      
    • #1331801

      Andrew

      I don’t doubt there are more lines of code than needed but the macros do work nicely. The users love them.

      Yes I should have gone for percentages but simply applying column widths but no table width does work. When the macro runs it specifies the sizes. With percentages they would have just resized I guess. I will fix that next time I work on the macros.

      Thank you.

    Viewing 2 reply threads
    Reply To: Portrait / Landscape Macro Problem

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

    Your information: