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