HOW TO

Activate a data frame programmatically in ArcMap

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS versions 8.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 a code sample that shows how to activate the selected data frame using VBA.

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. Start 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 'How to create custom commands with VBA'.
  1. Right-click the UIButtonControl and select View Source.
  2. Copy this code into the UIButtonControl's click event.
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Set pMxDoc = ThisDocument
    
'Get the Currently selected map
Dim pCV As IContentsView
Set pCV = pMxDoc.CurrentContentsView
Dim pVar As Variant
If Not IsNull(pCV.SelectedItem) Then
  'Make sure the selected item is of type IMap
  If TypeOf pCV.SelectedItem Is IMap Then
     Set pMap = pCV.SelectedItem
  Else
    MsgBox "Please Select a Map"
    Exit Sub
 End If
Else
  MsgBox "Please select a Map"
  Exit Sub
End If
'Check to see if the selected map is the focus map
Dim pActiveView As IActiveView
Set pActiveView = pMxDoc.ActiveView
If Not pActiveView.FocusMap Is pMap Then
'Check for Layout View or Map View
   If TypeOf pActiveView Is IPageLayout Then
     Set pMxDoc.ActiveView.FocusMap = pMap
   Else
     Set pMxDoc.ActiveView = pMap
   End If
End If

Article ID:000003545

Software:
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic