Knowledge Base - Technical Articles

Technical Article   HowTo:  Calculate the area for a polygon graphic in ArcMap

Article ID: 21033
Software:  ArcGIS - ArcEditor 8.3, 8.1, 8.1.2, 8.2, 9.0, 9.1, 9.2, 9.3, 9.3.1 ArcGIS - ArcInfo 8.2, 9.0, 8.0.1, 8.0.2, 8.1, 8.1.2, 8.3, 9.1, 9.2, 9.3, 9.3.1 ArcGIS - ArcView 8.3, 8.1, 8.1.2, 8.2, 9.0, 9.1, 9.2, 9.3, 9.3.1
Platforms:  Windows NT 4.0, 2000, XP


Instructions provided describe how to create a custom button in ArcMap that returns the area of a selected polygon graphic.

  This code is not designed to find the area of polygon features in shapefiles, feature classes, or coverages. This code only determines the area of selected polygon graphic elements in a map document, such as those created with the graphic tools on the Drawing toolbar.


  1. Start ArcMap.
  2. Create a new UIButtonControl. Select Tools > Customize to open the Customize dialog box.
  3. Click the Commands tab.
  4. Select UIControls from the Categories list box.
  5. Select the format that the button will be saved to from the 'Save In' drop-down menu.

    - Select Untitled to save to the current map document.
    - Select Normal to save to all ArcMap documents on the machine.
  6. Click New UIControl.
  7. Click UIButtonControl > Create.
  8. Drag the new UIButtonControl to the desired toolbar.
  9. Close the Customize dialog box.

      For more information on creating a UIControl, see the ArcGIS Desktop Help topic "How to create custom commands with VBA."

  10. Right-click the UIButtonControl and select 'View Source'.
  11. Copy this code into the UIButtonControl's click event. -show me-

    Dim pApp As IApplication
    Set pApp = Application

    '-- Get the map document
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument

    '-- Get the graphics container for the active view
    Dim pAv As IActiveView
    Set pAv = pDoc.ActiveView
    Dim pGc As IGraphicsContainerSelect
    Set pGc = pAv.GraphicsContainer

    '--Make sure a graphic element is selected
    If pGc.ElementSelectionCount = 0 Then
    MsgBox "Please select a graphic element"
    Exit Sub
    End If

    '-- Make sure only one element is selected
    Dim pElem As IElement
    If pGc.ElementSelectionCount > 1 Then
    MsgBox "Only one element can be selected"
    Exit Sub
    End If

    '-- Get the area for the selected element
    Dim pPoly As IPolygon
    Dim pArea As IArea
    Set pElem = pGc.SelectedElement(0)

    If TypeOf pElem.Geometry Is IPolygon Then
    Set pArea = pElem.Geometry
    '-- Send the area to the status bar
    pApp.StatusBar.Message(0) = "Element Area : " & pArea.Area
    '-- or a message box
    MsgBox "Element Area: " & pArea.Area
    End If

  12. Select a polygon graphic and press the UIButtonControl. The area is reported in the lower-left status bar as 'Element Area', as well as in a pop-up message box.

Related Information

Created: 11/28/2001
Last Modified: 5/3/2011

Article Rating: (11)
If you would like to post a comment, please login


By Anonymous - 07/26/2009 2:58 AM

The article is incorrect or the solution didn’t work.

When I try to use the Dim pArea as IArea If TypeOf pElem.Geometry is IPolygon Then Set pArea = pElem.Geometry End If code block I get a type mismatch at the line inside the if clause. Looking at the online information on IGeometry and IArea I'm not surprised about this. However, I still can't figure out how to calculate the area of a graphics feature programmatically - I hoped this article would help, but it hasn't. Is the code example wrong?

By Anonymous - 04/19/2007 3:51 PM

The article needs to be updated.

Since this article only deals with calculating area for graphics, it should point to the equivalent article for doing the same for feature classes (shapfiles, etc).

By Anonymous - 02/01/2006 1:05 PM

I'm getting area values of 9.500079 e-2 for a polygon. What are the area units supposed to be? Thanks!


By Anonymous - 03/20/2005 7:34 AM

When I select a polygon, then click the UIBottonControl, it just tells me to select a graphic element - BUT I ALREADY DID!! Surely there is an easier way to simply find the area of a polygon!!!

By Anonymous - 02/11/2005 6:15 AM

The VB code given in the article does not work with ArcView 8.3 (Error message "Runtime Error 5"). Could the article be updated? Simple measurement of polygon area is an important task.

By Anonymous - 11/03/2004 9:26 AM

Helpful except there seems to be a bug I don't know how to fix, at the line: Set pElem = pGc.SelectedElement(0) Please correct this soon!

By Anonymous - 09/30/2004 11:07 AM

I am getting a runtime error on the line Set pElem = pGc.SelectedElement(0) Is there a correction for this? Thanks, April

By Anonymous - 03/23/2004 3:07 PM

Very helpful - thank you What are the units of area in? Can this be changed? Regards Jason Carroll


By Anonymous - 03/12/2004 5:52 AM

I am looking for some help in figuring out this calculate polygon area code. I am new at Visual Basic. Does it matter what platform I am using. I see that is it being used in the forum in Windows NT, I am using Windows XP. I am getting an error on the following line in the following code: Set pElem = pGc.SelectedElement(0) The code is as follows: Private Sub Calculate_Poly_Area_Click() Dim pApp As IApplication Set pApp = Application '-- Get the map document Dim pDoc As I

By Anonymous - 03/01/2004 3:31 PM

This did not work for me. I'm not good with VBE but tried it several different ways. I've been successful at 'stealing' other code. Perhaps there's something wrong with this? I would REALLY like to do this however, so please reply. THanks Colin

By Anonymous - 12/09/2003 11:34 AM

Has this procedure been further debugged? The VBA editor was looking for an "end sub" command at the end of the program. I did this and other compile errors occured. Thank you


By Anonymous - 12/01/2003 9:15 AM

It Doesn't work, It's not recognizing the IElement. (this should be built into arcmap, this is an advantage mapinfo (just double click on the polygon) and all the other Gis competetors have over you.)

By Anonymous - 07/09/2003 6:29 AM

The article was very helpful and installation was simple. Is there a way for the area to be given in acres instead of squure feet


By Anonymous - 04/04/2003 11:45 AM


By Anonymous - 04/03/2003 6:18 AM


By Anonymous - 04/02/2003 2:56 PM

This script doesn't work. When I pasted it into VB Editor I was given an error 5. The problem is with this line - Set pElem = pGc.SelectedElement(0) I don't know much about VB, so can you please tell me how to fix this? Thank you

By Anonymous - 04/02/2003 1:18 PM

I received an error message on the line "Set pElem = pGc.SelectedElement(0)

By Anonymous - 04/01/2003 9:12 PM

This is just what I was looking for! However after following the above procedures I seem to get an error message as follows: Run-time error '5': Invalid procedure call or argument When I hit the debugging button visual basic points me to the following line of code: Set pElem = pGc.SelectedElement(0) Please help!!! This tool would be a great help to me!! Cheers, Marcela Alvarez.


By Anonymous - 04/01/2003 1:54 AM

This script will be very useful to my delegates, however, which units it the size of the polygon being reported as? Changing the units of the data frame makes no difference. If the units are not coming from the dataframe, and cannot be set elsewhere the tool has limited use. Why would someone want to know the area of a poly in screen units?


By Anonymous - 03/31/2003 7:26 PM

Using ArcGis 8.2, this script generates a "runtime error 5" that points to the line in the last sub: Set pElem = pGc.SelectedElement(0) Is there a correction for this?

By Anonymous - 03/27/2003 11:14 AM

Runtime error '5' Invalid procedure call or argument at Set pElem = pGc.SelectedElement(0) How do I correct this?

By Anonymous - 03/25/2003 11:43 AM

It was quite easy to follow. But I was wishing it could calculate polygonal features and not just graphics the user draws.


By Anonymous - 02/10/2003 1:40 PM

tried it and I failed

By Anonymous - 01/31/2003 11:51 AM


By Anonymous - 01/31/2003 8:10 AM

I was just going to look this one up and, voila!, there it was on the opening screen. Good notes, very helpfull in assessing areas of impact :)