How to activate a data frame


The following code shows you how to activate the last data frame (map) in the map document.

How to use

  1. Open a map document with more than one dataframe.
  2. Copy-paste this procedure into ArcMap's VB Editor.
  3. Run the procedure.
[VBA]
Public Sub ActiveDataFrame()
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    Dim pMaps As IMaps
    Set pMaps = pMxDoc.Maps
    
    
    Dim pMap As IMap
    Set pMap = pMaps.Item(pMaps.Count - 1)
    Dim pActiveView As IActiveView
    Set pActiveView = pMxDoc.ActiveView
    
    If TypeOf pActiveView Is IPageLayout Then
        Set pMxDoc.ActiveView.FocusMap = pMap
    Else
        Set pMxDoc.ActiveView = pMap
    End If
    
End Sub