How to create a toolbar programmatically


The CreateToolbar VBA macro creates a new toolbar called MyToolBar in ArcMap and then adds the ArcMap AddData and ZoomFullExtent commands to the toolbar. The toolbar is then docked on the right side of the application.  
All programmatic customizations are temporary. If you programmatically customize ArcMap, these changes will only appear while the current document is open in the current ArcMap session. Programmatic changes are never saved in the document or templates. Once you close that document or shutdown ArcMap, the changes are removed. If you are customizing ArcCatalog, these changes will only appear during the current ArcCatalog session.

How to use

  1. Paste this code into a module in the Visual Basic Editor for ArcMap.
  2. Run the CreateToolbar macro.
  3. You should see the new toolbar docked on the right side of the application window.
[VBA]
Public Sub CreateToolBar()
    Dim pDoc As IDocument
    Dim pCmdBars As ICommandBars
    Dim pCmdBar As ICommandBar
    
    Set pDoc = Application.Document
    Set pCmdBars = pDoc.CommandBars
    Set pCmdBar = pCmdBars.Create("MyToolBar", esriCmdBarTypeToolbar)
    ' The built in ArcID module is used to find the ArcMap commands.
    pCmdBar.Add ArcID.File_AddData
    pCmdBar.Add ArcID.PanZoom_FullExtent
    pCmdBar.Dock esriDockRight
End Sub