HOW TO
This document contains a VBA example that zooms to the XY domain of the selected layer in ArcMap's Table of Contents.
Note:
Code in ThisDocument code module will only run in the current map document. To store the code in all your map documents, open the Normal.mxt ThisDocument code module.
Code:
Public Sub ZoomToDomainExtent()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView
Dim pContentsView As IContentsView
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pActiveView = pMap
Set pContentsView = pMxDoc.CurrentContentsView
Dim pLayer As ILayer
Dim pDataSet As IDataset
Dim pFeatureLayer As IFeatureLayer
Dim pGeoDataset As IGeoDataset
If Not TypeOf pContentsView.SelectedItem Is ILayer Then Exit Sub
Set pLayer = pContentsView.SelectedItem
Set pFeatureLayer = pLayer
Set pGeoDataset = pFeatureLayer
Dim pSpatialReference As ISpatialReference
Dim pEnvelope As IEnvelope
Set pSpatialReference = pGeoDataset.SpatialReference
Set pEnvelope = New Envelope
Dim dXmax As Double
Dim dYmax As Double
Dim dXmin As Double
Dim dYmin As Double
pSpatialReference.GetDomain dXmin, dXmax, dYmin, dYmax
pEnvelope.XMax = dXmax
pEnvelope.YMax = dYmax
pEnvelope.XMin = dXmin
pEnvelope.YMin = dYmin
pActiveView.Extent = pEnvelope
pActiveView.Refresh
End Sub
Article ID:000005068
Get help from ArcGIS experts
Download the Esri Support App