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
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic 'How to create custom commands with VBA'.
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
Get help from ArcGIS experts
Download the Esri Support App