The following code shows you how to create a new data frame (map) and add it to your document. The new data frame is then activated. This mimics the functionality of the Insert > Dataframe menu item in ArcMap.
How to use
- Copy-paste this procedure into the VBA Editor in ArcMap.
- Run the procedure.
Private Sub CreateAndAddNewMap()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
'Create a new map
Dim pMap As IMap
Set pMap = New Map
pMap.Name = "My Map"
'Create a new MapFrame and associate map with it
Dim pMapFrame As IMapFrame
Set pMapFrame = New MapFrame
Set pMapFrame.Map = pMap
'Set the position of the new map frame
Dim pElement As IElement
Dim pEnv As IEnvelope
Set pElement = pMapFrame
Set pEnv = New Envelope
pEnv.PutCoords 0, 0, 5, 5
pElement.Geometry = pEnv
'Add mapframe to the layout
Dim pGraphicsContainer As IGraphicsContainer
Set pGraphicsContainer = pMxDoc.PageLayout
pGraphicsContainer.AddElement pMapFrame, 0
'Make the newly added map the focus map
Dim pActiveView As IActiveView
Set pActiveView = pMxDoc.ActiveView
If TypeOf pActiveView Is IPageLayout Then
Set pActiveView.FocusMap = pMap
Else
Set pMxDoc.ActiveView = pMap
End If
'Refresh ActiveView and TOC
pActiveView.Refresh
pMxDoc.CurrentContentsView.Refresh 0
End Sub