Changing page size dynamically

Discussion created by ebregant on Jul 11, 2011
I have a macros function that worked in 9.3 but it is sketchy in 10. When I run the macros it brings up the window where I can type my desired page size in. The problem happens when I edit some data or change something on the mxd. When I run the macros, all of my data and the data frame shrinks down into the bottom corner. It never used to do this in 9.3! Any ideas?

Sub PageSize()
  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
  End If
  Dim pMxDocument As IMxDocument
  Set pMxDocument = ThisDocument
  Dim pGraphicContainer As IGraphicsContainer
  Set pGraphicContainer = pMxDocument.PageLayout
  Dim pElement As IElement
  Dim pFrameElement As IFrameElement
  Dim pEnvelope As IEnvelope
  Set pElement = pGraphicContainer.Next
  Do While Not pElement Is Nothing
      If TypeOf pElement Is IMapFrame Then
          Set pFrameElement = pElement
          Set pEnvelope = pElement.Geometry.Envelope
          With pEnvelope 'set position in page unit
              .XMin = 0
              .XMax = pDialog.X
              .YMin = 0
              .YMax = pDialog.Y
          End With
          pElement.Geometry = pEnvelope
      End If
      Set pElement = pGraphicContainer.Next
  If TypeOf pMxDocument.ActiveView Is IPageLayout Then pMxDocument.ActiveView.Refresh
End Sub