CommandBarControls Collection Object

CommandBarControls Collection Object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.


CommandBars collection (CommandBar object)
Aa831765.parchild(en-us,office.10).gifCommandBarControls collection (CommandBarControl object),office.10).gifAa831765.parmult(en-us,office.10).gifCommandBarButton object,office.10).gifAa831765.parmult(en-us,office.10).gifCommandBarComboBox object,office.10).gifAa831765.parchild(en-us,office.10).gifCommandBarPopup object

A collection of CommandBarControl objects that represent the on a command bar.

Using the CommandBarControls Collection

Use the Controls property to return the CommandBarControls collection. The following example changes the caption of every control on the toolbar named "Standard" to the current value of the Id property for that control.

For Each ctl In CommandBars("Standard").Controls
    ctl.Caption = CStr(ctl.Id)
Next ctl

Use the Add method to add a new command bar control to the CommandBarControls collection. This example adds a new, blank button to the command bar named "Custom."

Set myBlankBtn = CommandBars("Custom").Controls.Add

Use Controls(index), where index is the caption or index number of a control, to return a CommandBarControl, CommandBarButton, CommandBarComboBox, or CommandBarPopup object. The following example copies the first control from the command bar named "Standard" to the command bar named "Custom."

Set myCustomBar = CommandBars("Custom")
Set myControl = CommandBars("Standard").Controls(1)
myControl.Copy Bar:=myCustomBar, Before:=1
© 2015 Microsoft