Execute Commands Programmatically

Created:11/07/1999
Description:

The ExecuteCmdCatalog VBA macro shows how to programmatically execute the built-in ArcCatalog Full Extent command. The ExecuteCmdArcMap VBA macro shows how to programmatically execute the built-in ArcMap Full Extent command. The built-in ArcID module is used to get the unique identifer of the command.

How to use:
  1. Paste the ExecuteCmdArcCatalog macro into a module in the Visual Basic Editor in ArcCatalog or paste the ExecuteCmdArcMap macro into a module in the Visual Basic Editor in ArcMap.
  2. Run the macro to execute the command.
Sub ExecuteCmdCatalog()
  Dim pDoc As IDocument
  Dim pCmdBars As ICommandBars
  Dim pItem As ICommandItem
  
  Set pDoc = Application.Document
  Set pCmdBars = pDoc.CommandBars
  Set pItem = pCmdBars.Find(ArcID.Geography_FullExtent)
  pItem.Execute
End Sub


Sub ExecuteCmdArcMap()
  Dim pdoc As IDocument
  Dim pCmdBars As ICommandBars
  Dim pItem As ICommandItem
  
  Set pdoc = Application.Document
  Set pCmdBars = pdoc.CommandBars
  Set pItem = pCmdBars.Find(ArcID.PanZoom_FullExtent)
  pItem.Execute
End Sub