h1

Word: Macro to insert a landscape page

May 14, 2019

A client wanted an easy way for her staff to insert a landscape page into a report without messing up the headers and footers. I recorded a macro that does just that, but it relies on headers and footers being laid out using the alignment tabs, not borderless tables. Alignment tabs are much better than inserting tabs yourself as they automatically adjust if you change the page layout.

Note: If you use borderless tables for your headers and footers, this macro will still work, but you’ll have to manually turn off the Link to Previous options for the landscape page’s headers and footers and also for the following portrait page. I might see if I can tweak the macro to do that—if so, I’ll write it up as a separate blog post.

Step 1: Set up alignment tabs for the headers and footers

  1. Open a new Word document (or the template if you want to set this up in your template).
  2. Double-click in the header area to open the header. The cursor will be at the left margin.
  3. Optional: Add any text you want positioned at the left.
  4. In the Header & Footer Tools tab > Position group, click Insert Alignment Tab.
  5. By default the next position is Center. Make sure it’s selected, then click OK.
  6. Optional: Add any text you want positioned in the centre.
  7. Click Insert Alignment Tab again.
  8. Select Right then click OK.
  9. Optional: Add any text you want positioned at the right.
  10. In the Header & Footer Tools tab > Navigation group, click Go to Footer.
  11. Repeat steps 3 to 9 above for the footers.
  12. Double-click in the main body of the document to close the header/footer area.

Step 2: Install and run the macro

The macro you will use to insert a landscape section is listed below these steps.

  1. Go to the View tab >Macros group, then select View Macros from the drop-down list.
  2. In the Macro Name field, type InsertLandscape (if you have other macros listed, the one listed first will be in that field—just type over it)
  3. Click Create. This opens the Visual Basic for Applications (VBA) window, with these lines already inserted:
    Sub InsertLandscape()
    ‘ InsertLandscape macro
    End Sub
  4. Copy the macro below this set of steps.
  5. Paste it into the blank area above End Sub.
  6. Save the change and close the VBA window. (If you’re working in a template and only want this macro available to documents based on that template, then select the template name from the Macros in field.)
  7. Test the macro by running it:
    • Go to the View tab >Macros group, then select View Macros from the drop-down list.
    • Select the InsertLandscape macro.
    • Click Run.
  8. A landscape section should be inserted into your document, and the headers and footers should all align correctly for the landscape section.

Macro

' Inserts a landscape section, adjusts headers and footers
' Created by Rhonda Bracey, CyberText Consulting, May 2019
'
Selection.TypeParagraph
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.TypeParagraph
Selection.TypeParagraph
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.MoveUp Unit:=wdLine, Count:=2
If Selection.PageSetup.Orientation = wdOrientPortrait Then
Selection.PageSetup.Orientation = wdOrientLandscape
Else
Selection.PageSetup.Orientation = wdOrientPortrait
End If
ActiveWindow.ActivePane.SmallScroll Down:=-3
ActiveWindow.ActivePane.LargeScroll Down:=1

What this macro does:

  • Inserts an empty paragraph.
  • Inserts a Next Page section break.
  • Inserts two more empty paragraphs.
  • Inserts another Next Page section break.
  • Moves the cursor back up to one of the empty paragraphs between the two section breaks.
  • Changes the area between the section breaks to Landscape orientation.

One comment

  1. Thanks for all you do, Rhonda. I look forward to reading your posts, they are usually relevant to what I’m working on.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: