Page Setup VBA Microsoft Word Add-in VBA (Visual Basic for Applications)

Page Setup VBA Microsoft Word Add-in VBA (Visual Basic for Applications)

PageSetup

The PageSetup object exposes various Page Setup methods and properties of a document (such as left margin, bottom margin, and paper size) as properties. Let’s put some code around to play with Page Setup in Word. In the below example we will change the page orientation from Portrait to Landscape.

Code example

Public Sub PageSetup()
    
    'Declare page setup object
    Dim oPageSetup As PageSetup
    
    'Bind object
    Set oPageSetup = ActiveDocument.PageSetup
    
    'Change orientation
    If oPageSetup.Orientation = wdOrientPortrait Then
        oPageSetup.Orientation = wdOrientLandscape
    End If
End Sub

To verify do the followings:

  1. Click on Layout tab
  2. Click on Orientation button under Page Setup group
  3. The selected orientation would be enabled in the button as shown below

Next >> Understand Page Object in Word Add-in code example

Leave a Reply

Your email address will not be published.