Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2014, 01:05 AM
Catty Catty is offline Macro to insert Landscape page Windows 7 32bit Macro to insert Landscape page Office 2010 32bit
Advanced Beginner
Macro to insert Landscape page
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default Macro to insert Landscape page

Hi All,



I have a macro - InsertLandscape, which inserts a landscape page wherever the cursor is on a document. The problem with this macro is that if I try to insert a landscape page right after a portrait page...my margins and headers reflect those of the portrait page. How do I modify my macro to correctly align the margins and headers to fit on the landscape page?

Below is my macro:

Code:
sub InsertLandscape

On Error Resume Next
'   Add Section Break Next Page
        Selection.InsertBreak Type:=wdSectionBreakNextPage
    If Selection.PageSetup.Orientation = wdOrientPortrait Then
        Selection.PageSetup.Orientation = wdOrientLandscape
    Else
        Selection.PageSetup.Orientation = wdOrientPortrait
    End If
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientLandscape
        .TopMargin = CentimetersToPoints(1)
        .BottomMargin = CentimetersToPoints(1)
        .LeftMargin = CentimetersToPoints(1.5)
        .RightMargin = CentimetersToPoints(1.5)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(4)
        .FooterDistance = CentimetersToPoints(0.6)
        .PageWidth = CentimetersToPoints(29.7)
        .PageHeight = CentimetersToPoints(21)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        '.DifferentFirstPageHeaderFooter = False
        .DifferentFirstPageHeaderFooter = True
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With
    
Selection.InsertBreak Type:=wdSectionBreakNextPage

' Unlink To Previous footer
  Dim myRng As Word.Range
  Set oDoc = ActiveDocument
  
' Get the index number of the added section
  i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
    With oDoc.Sections(i)
        For j = 1 To 3
      .Headers(j).LinkToPrevious = False
      .Footers(j).LinkToPrevious = False
        Next j
    End With
  
'   Note: j provides the constant value to unlink all three header\footer types

lbl_Exit:

' Continue page numbering
'
    With Selection.Sections(1).Headers(1).PageNumbers
        .NumberStyle = wdPageNumberStyleArabic
        .HeadingLevelForChapter = 0
        .IncludeChapterNumber = False
        .ChapterPageSeparator = wdSeparatorHyphen
        .RestartNumberingAtSection = False
        .StartingNumber = 0
    End With
        
    Exit Sub
End Sub
Reply With Quote
  #2  
Old 05-05-2014, 03:42 AM
macropod's Avatar
macropod macropod is offline Macro to insert Landscape page Windows 7 32bit Macro to insert Landscape page Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You need to change your macro to set the left, right, top, bottom & gutter margins to whatever you require for a landscape page. In this case, I suspect it's just a matter of swapping the CentimetersToPoints(1) and CentimetersToPoints(1.5) settings.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Landscape Orientation - Rotate page so top of landscape is printed on left side swifty2010 Word 17 06-11-2022 05:50 PM
Macro to open the Insert>Cover Page window /dialog box Catty Word VBA 3 02-24-2014 06:02 PM
Macro to insert Landscape page Prints in half page landscape lostsoul62 Excel 2 07-22-2013 01:24 PM
Macro to insert new page... samanthaj Word 17 01-31-2012 01:53 PM
Macro to insert Landscape page Word 97, Landscape page orientation issue RodA Word 2 03-07-2011 04:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft