Page Setup Object

If you need to programmatically read or set various options available in the PageSetup dialog box (such as paper size, orientation, margins, print area, and so on), use the PageSetup property to return a PageSetup object. The following example procedure prints several settings from the Page Setup dialog to the Immediate window and asks whether to set the orientation to portrait mode.

Sub ReadPageSetup()

Dim objPageS As PageSetup

Set objPageS = ActiveSheet.PageSetup With objPageS

Debug.Print "Orientation:"; .Orientation Debug.Print "Paper Size:"; .PaperSize Debug.Print "Print Area: "; .PrintArea Debug.Print "Left Margin: "; .LeftMargin Debug.Print "Top Margin: "; .TopMargin Debug.Print "Print Gridlines: "; .PrintGridlines .Orientation = xlLandscape If .Orientation <> xlPortrait Then

If MsgBox("Do you want to set the orientation " & _ "mode to Portrait?", vbYesNo + vbQuestion) = vbYes Then

.Orientation = xlPortrait End If End If End With End Sub

0 0

Post a comment