Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing an application where one of the things it does is create a point then creates buffer (which is a graphic) at the specific point, what I want to do is when the buffer has been created, is to zoom to the extent of the buffer.

I have tried the following code but it doesn't seem to work

Dim penv2 As IEnvelope
Set penv2 = New Envelope
Set penv2 = pActiveView.extent
Dim pArea As IArea
Set pArea = pElement.Geometry.Envelope
penv2.CenterAt pArea.Centroid            

I've also tried

Dim penv2 As IEnvelope
Set penv2 = pElement.Geometry.Envelope
pActiveView.Extent = penv2 

But nothing happens. Any ideas on where I am going wrong?


share|improve this question
up vote 1 down vote accepted

This works for me:

Option Explicit
Sub ZoomToElement()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    Dim pGCS As IGraphicsContainerSelect
    Set pGCS = pMxDoc.FocusMap

    If pGCS.ElementSelectionCount <> 1 Then
        Debug.Print "select just one element first"
        Exit Sub
    End If

    Dim pEnv As IEnvelope
    Set pEnv = pGCS.SelectedElement(0).Geometry.Envelope

    Dim pAV As IActiveView
    Set pAV = pMxDoc.FocusMap

    pAV.Extent = pEnv
End Sub
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.