Add (CommandBarControls)

This method adds a CommandBarControl object to the CommandBarControls collection of a CommandBar control.

Syntax

cmdbarctrls.Add([type], [key])

Parameters

cmdbarctrls
Required. Name of a CommandBarControls collection.
type
Optional. Value that determines the type of control being added.
key
Optional. Unique string for the Key property of the new CommandBarControl.

Return Value

Reference to the new control, which is a CommandBarButton, CommandBarComboBox, or CommandBarMenuBar.

Remarks

The following table shows the possible values for the type parameter.

Constant
Value
Description
cbrButton 0 The control added is a CommandBarButton.
cbrComboBox 1 The control added is a CommandBarComboBox.
cbrMenuBar 2 The control added is a CommandBarMenuBar.

You can add controls in any order. If the value for before is not a valid key for a control in the collection, Add raises an error.

The following code example shows how to add a button.

Dim B As CommandBarButton
Set B = CommandBar1.Controls.Add(cbrButton)
B.Style = cbrCheck