Dave H
Dave H

Reputation: 1

Excel VBA Ignoring PageSetup Changes

I have a simple Excel Macro (below) that just changes the orientation from Portrait to Landscape. I used the Excel "record macro" tool, but when I use this macro, it ignores the commands. Has anyone else seen this? And, is there a good solution?

Sub Writedown_Format_Landscape()
'
' Writedown_Format_Landscape Macro
Range("A1").Select

Application.PrintCommunication = False
With ActiveSheet.PageSetup
    .PrintTitleRows = "$1:$1"
    .PrintTitleColumns = ""
End With

Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False

With ActiveSheet.PageSetup
    .LeftHeader = "&D - &T"
    .CenterHeader = "&F"
    .RightHeader = "&P / &N"
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints(0.5)
    .BottomMargin = Application.InchesToPoints(0.25)
    .HeaderMargin = Application.InchesToPoints(0.25)
    .FooterMargin = Application.InchesToPoints(0.25)
    .PrintHeadings = False
    .PrintGridlines = True
    .PrintComments = xlPrintNoComments
    .CenterHorizontally = True
    .CenterVertically = False
    .Orientation = xlLandscape
    .Draft = False
    .PaperSize = xlPaperLetter
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = 100
End With

Range("A1").Select

End Sub

Upvotes: 0

Views: 398

Answers (1)

Limak
Limak

Reputation: 1521

The only line you need from this whole recorded macro is:

ActiveSheet.PageSetup.Orientation = xlLandscape

Please change the sheet reference, just to be sure that you are interacting with correct sheet. You need to type name of your sheet inside the brackets:

Sheets("YourSheetName").PageSetup.Orientation = xlLandscape

Now, check once more on print preview, if there is no change.

Upvotes: 1

Related Questions