HOW TO

Find the center point of an ArcMap data frame

Last Published: April 25, 2020

Summary

The following VBA code calculates the center point of a data frame. The coordinates are in the map units of the data frame.

Procedure

Activate the data frame from which you want the center point coordinates. You must be in Data View when using this code. If you are in Layout View the center point of the layout page in page units will be returned.

  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument. Right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer
    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.

  4. Copy the following code into the code module.
    Code:
    Sub ReturnCenter()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = Application.Document
    Dim pEnv As IEnvelope
    Set pEnv = pMxDoc.ActivatedView.Extent
    Dim pX As Double
    Dim pY As Double
    pX = (pEnv.XMax + pEnv.XMin) / 2
    pY = (pEnv.YMax + pEnv.YMin) / 2
    MsgBox pX & ", " & pY
    End Sub

  5. Close the Visual Basic Editor.
  6. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.



    The center point coordinates will be shown in a message box.

Article ID:000005582

Software:
  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic