How to create a spatial bookmark


This sample creates a spatial bookmark based on the focus map's current extent. Bookmarks make it easy to jump to specific saved extents because they save extents along with a name identifying them.
In ArcMap, bookmarks are accessible via the Bookmarks menu under the View menu. ArcMap also has a bookmark manager which allows users to delete undesired bookmarks.

How to use

  1. Paste the code into VBA
  2. Modify the text string holding the extent name as desired
  3. Execute the routine
[VBA]
Public Sub AddSpatialBookMark()
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pActiveView As IActiveView
    Dim pAreaOfInterest As IAOIBookmark
    Dim pMapBookmarks As IMapBookmarks
    
    Set pMxDoc = Application.Document
    Set pMap = pMxDoc.FocusMap
    Set pActiveView = pMap
    
    'Create a new bookmark and set it's location to the focus map's current extent
    Set pAreaOfInterest = New AOIBookmark
    Set pAreaOfInterest.Location = pActiveView.Extent
    'Give the bookmark a name
    pAreaOfInterest.Name = "My bookmark"
    'Add the bookmark to the map's bookmark collection  'This will add the bookmark to the Bookmarks menu accessible from the View menu
    Set pMapBookmarks = pMap
    pMapBookmarks.AddBookmark pAreaOfInterest
    
End Sub