Transform Rectangle from Page to Map Units


You can use this function to transform an envelope (rectangle) from page units to map units.
ArcView: VBA

Platforms: Windows

Minimum ArcGIS Release: 8.2

How to use:
  1. Copy-paste this sample's code into a module in your Visual Basic Editor.
  2. Call this procedure by passing in an envelope in page units. This envelope is transformed into map units.
Private Sub TransformRectFromPageToMapUnits(pEnv As IEnvelope)
  'Get the active views
  Dim pLayoutView As IActiveView
  Dim pMapView As IActiveView
  Dim pMap As IMap
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
  Set pMap = pMxDoc.FocusMap
  Set pLayoutView = pMxDoc.PageLayout
  Set pMapView = pMap

  'Get the display transformations
  Dim pPageTransformation As IDisplayTransformation
  Dim pMapTransformation As IDisplayTransformation
  Set pPageTransformation = pLayoutView.ScreenDisplay.DisplayTransformation
  Set pMapTransformation = pMapView.ScreenDisplay.DisplayTransformation
  'Transform envelope from page to map coordinates
  Dim Rect As tagRECT
    'Transform from Page units to Device units
  pPageTransformation.TransformRect pEnv, Rect, esriTransformToDevice + esriTransformPosition
    'Transform from Device units to Map units
  pMapTransformation.TransformRect pEnv, Rect, esriTransformToMap + esriTransformPosition

End Sub