Zoom To Layer (VBA)

Discussion created by jmadero on May 4, 2012
Latest reply on May 9, 2012 by jbarrette-esristaff
Hi All,

Let me start by saying I have never coded in GIS programs before, I know basic, some C/C++, and a few others I've dabbled in.

What I'm looking for is how would I go about automating a query on a layer, zoom to the layer, change a number that is on the map (MAP # which is based on a field that is located in the zoomed to layer), then print it. For the last couple years I've had to manually print out hundreds of maps for this project and I think it can be automated relatively easily.

Thanks in advance :)

I think doing this one step at a time would be best. So how do I just zoom to a layer, I have this:

Sub Multiple_Polls()
Dim pDoc As IMxDocument

Set pDoc = ThisDocument

Dim pMap As IMap

Set pMap = pDoc.FocusMap

Dim pLayer As IFeatureLayer

Dim pFSel As IFeatureSelection

Set pLayer = pMap.Layer(3)

Set pFSel = pLayer

'Get the selected features

Dim pSelSet As ISelectionSet

Set pSelSet = pFSel.SelectionSet

Dim pEnumGeom As IEnumGeometry

Dim pEnumGeomBind As IEnumGeometryBind

Set pEnumGeom = New EnumFeatureGeometry

Set pEnumGeomBind = pEnumGeom

pEnumGeomBind.BindGeometrySource Nothing, pSelSet

Dim pGeomFactory As IGeometryFactory

Set pGeomFactory = New GeometryEnvironment

Dim pGeom As IGeometry

Set pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom)

pDoc.ActiveView.Extent = pGeom.Envelope

End Sub

But how do I set the correct layer, I changed this line:

Set pLayer = pMap.Layer(3)

to different numbers but all just seem to refresh the map, not actually zoom to layer. Thanks in advance