To add a new toolbar button to a toolbar, use the AddToolbarButton method. This method creates a new ToolbarItem object and adds it to the designated toolbar.
You should only add buttons to a toolbar while the toolbar is visible.
The AddToolbarButton method takes five parameters as input: Index, Name, HelpString, Macro, and FlyoutButton.
Once a toolbar button has been created, you cannot change the index of the button through the Index property. To change the index of an existing toolbar button, you must delete and re-add the toolbar button to a different position, or add or delete surrounding toolbar buttons until a proper placement is achieved.
Once a toolbar button has been created, you can change the name using the Name parameter.
Once a toolbar button has been created, you can change the help string for the button using the HelpString parameter.
Once a Toolbar button has been created, you can change the macro for the button using the Macro parameter.
This example creates a new toolbar and adds a button to the toolbar. The button is assigned a macro that will execute the OPEN command when the button is selected.
Sub Ch6_AddButton() Dim currMenuGroup As AcadMenuGroup Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0) ' Create the new toolbar Dim newToolbar As AcadToolbar Set newToolbar = currMenuGroup.Toolbars.Add("TestToolbar") ' Add a button to the new toolbar Dim newButton As AcadToolbarItem Dim openMacro As String ' Assign the macro the VB equivalent of "ESC ESC _open " openMacro = Chr(3) + Chr(3) + "_open " Set newButton = newToolbar.AddToolbarButton _ ("", "NewButton", "Open a file.", openMacro) End Sub