HOW TO

Programmatically add a neatline to the active data frame in ArcMap

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS versions 8.x and 9.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

This article contains sample code that adds a neatline to the active data frame.

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

Procedure

  1. Open ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl
Note:
For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  1. Right-click the UIButtonControl and select View Source.
  2. Paste this code into the UIButtonControl's click event.
Sub AddNeatline()

Dim x As Double

'Change x to equal the distance of
'the neatline from extent envelope
x = 0.5

Dim pMxDoc As IMxDocument
Dim pMxApp As IMxApplication
Dim pActiveView As IActiveView
Dim pMap As IMap
Dim pPageLayout As IPageLayout
Dim pDisplay As IScreenDisplay
Dim pGC As IGraphicsContainer
Dim pElem As IElement
Dim pMapFrame As IMapFrame
Dim pEnv As IEnvelope
Dim pElemEnvelope As IEnvelope

Set pMxApp = Application
Set pMxDoc = ThisDocument
Set pPageLayout = pMxDoc.PageLayout
Set pGC = pPageLayout
Set pDisplay = pMxApp.Display

'Get Active Map name
Dim strMapName As String
strMapName = ""

Set pMap = pMxDoc.FocusMap
strMapName = pMap.Name

'Get the active map's Map Frame out of the graphics container
pGC.Reset
Set pElem = pGC.Next
Do While (Not pElem Is Nothing)
    If (TypeOf pElem Is IFrameElement) Then
        If (TypeOf pElem Is IMapFrame) Then
            Set pMapFrame = pElem
            If strMapName = pMapFrame.Map.Name Then
                Set pElemEnvelope = pElem.Geometry.Envelope
                Set pEnv = pMapFrame.MapBounds
            End If
        End If
    End If
    Set pElem = pGC.Next
Loop

Dim pRect As IRectangleElement
Set pRect = New RectangleElement

Dim pElement As IElement
Set pElement = pRect

'Set the Neatline distance from the frame border
pElemEnvelope.XMin = pElemEnvelope.XMin - x
pElemEnvelope.YMin = pElemEnvelope.YMin - x
pElemEnvelope.XMax = pElemEnvelope.XMax + x
pElemEnvelope.YMax = pElemEnvelope.YMax + x
pElement.Geometry = pElemEnvelope

'Set the Neatline symbology
Dim pRectSym As IFillShapeElement
Set pRectSym = pRect

'Set the style of the fill symbol
Dim pFillSymbol As ISimpleFillSymbol
Dim plinesymbol As ISimpleLineSymbol

Set pFillSymbol = New SimpleFillSymbol
Set plinesymbol = pFillSymbol.Outline

pFillSymbol.Style = esriSFSHollow
'Set the outline symbol
plinesymbol.Style = esriSLSSolid
plinesymbol.Width = 6
pFillSymbol.Outline = plinesymbol

'Set it all into the element
pRectSym.Symbol = pFillSymbol

'Draw the neat line
pElement.Activate pDisplay
pGC.AddElement pRect, 0
pMxDoc.ActiveView.Refresh
  
End Sub
  1. Close the Visual Basic Editor.
  2. Switch to layout view and press the UIButtonControl to insert a neatline into the active data frame.

Article ID:000004968

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