How to locate and execute a command on a toolbar


This sample illustrates how to programmatically execute existing commands on command bars within ArcMap.
The code samples in this section show the fundamentals of programming with ArcObjects. A careful reading of them gives you all the important concepts you need for developing with ArcObjects, as well as an introduction to the most important ArcObjects components.
The code can be typed or copied into the VBA environment in ArcMap or ArcCatalog, after which you can follow through with the VBA debugger.

How to use

  1. Add the code to the Click event of a command in ArcMap.
[VBA]
Dim pCommandItem As ICommandItem

Set pCommandItem = ThisDocument.CommandBars.Find(ArcID.Query_ZoomToSelected)
If (pCommandItem Is Nothing) Then Exit Sub
pCommandItem.Execute

Set pCommandItem = ThisDocument.CommandBars.Find(ArcID.ReportObject_CreateReport)
If (pCommandItem Is Nothing) Then Exit Sub
pCommandItem.Execute