CommandBarButton object (Office)

Represents a button control on a command bar.


The use of CommandBars in some Microsoft Office applications has been superseded by the new ribbon component of the Microsoft Office Fluent user interface. For more information, see Overview of the Office Fluent ribbon.


Use Controls(index), where index is the index number of the control, to return a CommandBarButton object. Note that the Type property of the control must be msoControlButton. Assuming that the second control on the command bar named Custom is a button, the following example changes the style of that button.

Set c = CommandBars("Custom").Controls(2) 
With c 
If .Type = msoControlButton Then 
    If .Style = msoButtonIcon Then 
        .Style = msoButtonIconAndCaption 
        .Style = msoButtonIcon 
    End If 
End If 
End With


You can also use the FindControl method to return a CommandBarButton object.

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.