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
- Paste the code into VBA.
- Execute the routine.
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