How to change the page size


This sample code changes the page layout's page size based on user input. A coordinate dialog is used to prompt the user for input. When the dialog is open, hitting the escape key will close the dialog without changing the page size. Hitting the return key will dismiss the dialog and change the page size.

How to use

  1. Paste the code into VBA.
  2. Execute the routine.
[VBA]
Public Sub ChangePageSize()
    Dim pMxDoc As IMxDocument
    Dim pPage As IPage
    Dim pDialog As ICoordinateDialog
    Dim pActiveView As IActiveView
    
    Set pMxDoc = Application.Document
    Set pActiveView = pMxDoc.PageLayout
    Set pPage = pMxDoc.PageLayout.Page
    Set pDialog = New CoordinateDialog
    
    If pDialog.DoModal("Enter new page size", 8.5, 11, 2, Application.hWnd) Then
        pPage.PutCustomSize pDialog.x, pDialog.y
        pActiveView.Refresh
    End If
    
End Sub