Applies To
ToolbarButtons Collection.
Description
Adds a new button to an existing toolbar. Returns a ToolbarButton object.
Syntax
object.Add(button, before, onAction, pushed, enabled, statusBar, helpContextID, helpFile)
object
Required. The ToolbarButtons object.
button
Optional. The button ID number, as an integer. If this argument is omitted, a gap is inserted in the toolbar. You can only insert a gap between two toolbar buttons (you cannot insert a gap at the beginning or at the end of the toolbar). To insert a button followed by a gap at the beginning of the toolbar, insert the new button first, and then insert the gap after the new button. For a complete list of button IDs available to Visual Basic, see Toolbar Button ID Values.
before
Optional. Specifies the new button position. The new button will be inserted before the button at this position. If this argument is omitted, the button is inserted at the end of the toolbar. Remember that gaps count as toolbar buttons; you cannot simply count buttons to get the button position. For example, if there is a gap between the first and second buttons on the toolbar, you must specify 3 for the before argument to insert a new button after the gap.
onAction
Optional. Specifies an initial value for the OnAction property, which is the name of the macro that runs when the button is clicked. If omitted with a built-in button, the button will have its built-in behavior. If omitted with a custom button, the Assign Macro dialog box is displayed when the button is first clicked.
pushed
Optional. Specifies an initial value for the Pushed property (True if the button appears pressed).
enabled
Optional. Specifies an initial value for the Enabled property (True if the button is enabled).
statusBar
Optional. Specifies help text to display in the status bar when the mouse cursor is positioned over the toolbar button. If omitted the default status bar text assigned to the macro is used.
helpContextID
Optional. Specifies the context ID for the custom help topic of the toolbar button. If omitted the default help context ID assigned to the macro is used.
helpFile
Optional. Specifies the help file name containing the custom help topic of the toolbar button. If omitted the default help file name assigned to the macro is used.
Remarks
The settings specified for the statusBar, helpContextID, and helpFile arguments override any per-macro options set by the macro specified by the onAction argument.
However, changing the macro options after the toolbar button has been added overrides the custom help arguments used with the Add method.
See Also
Enabled Property, MacroOptions Method, OnAction Property, Pushed Property.
Example
This example creates a new toolbar, adds the Camera button (button index number 228) to it, and then displays the new toolbar.
Set myNewToolbar = Toolbars.Add(Name:="My New Toolbar") myNewToolbar.ToolbarButtons.Add Button:=228 myNewToolbar.Visible = True