Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Portrait / Landscape Macro Problem

    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 Word\Startup 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.

    landscape001.png

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

    landscape002.png

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

    landscape003.png

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

    landscape004.png

    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.
    Attached Files Attached Files

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post
    ... 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!

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    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
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post
    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.

Posting Permissions

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