How to zoom to the extent of the first layer in a map


This sample zooms the focus map to the extent of a layer. For simplicity sake, the first layer in the map is used.

How to use

  1. Paste the code into VBA.
  2. Modify the code to get the desired layer.
  3. Execute the routine.
[VBA]
Public Sub ZoomToLayer()
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pActiveView As IActiveView
    
    Set pMxDoc = Application.Document
    Set pMap = pMxDoc.FocusMap
    Set pActiveView = pMap
    
    If pMap.Layer(0) Is Nothing Then Exit Sub
    pActiveView.Extent = pMap.Layer(0).AreaOfInterest
    pActiveView.Refresh
End Sub