This sample zooms to the extent of the layer selected in the table of contents. In this case, use IContentsView::SelectedItem on the TOCDisplayView object.
How to use
- Paste the code into VBA.
- Modify the code to get the desired layer.
- Execute the routine.
Public Sub ZoomToLayer2()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView
Dim pContentsView As IContentsView
Dim pLayer As ILayer
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pActiveView = pMap
Set pContentsView = pMxDoc.CurrentContentsView
If Not TypeOf pContentsView.SelectedItem Is ILayer Then Exit Sub
Set pLayer = pContentsView.SelectedItem
pActiveView.Extent = pLayer.AreaOfInterest
pActiveView.Refresh
End Sub