PageSetup.Orientation property (Excel)

Returns or sets an XlPageOrientation value that represents the portrait or landscape printing mode.



expression A variable that represents a PageSetup object.


This example sets Sheet1 to be printed in landscape orientation.

Worksheets("Sheet1").PageSetup.Orientation = xlLandscape

This example sets the currently active sheet to be printed in portrait orientation.

ActiveSheet.PageSetup.Orientation = xlPortrait

This procedure switches the orientation to the opposite option.

Sub SwitchOrientation()
    Dim ps As PageSetup
    Set ps = ActiveSheet.PageSetup

    If ps.Orientation = xlLandscape Then
        ps.Orientation = xlPortrait
        ps.Orientation = xlLandscape
    End If
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.