Execute Method (Command Bar Controls)

Applies To

CommandBarButton object, CommandBarComboBox object, CommandBarControl object, CommandBarPopup object.

Description

Runs the macro or built-in command assigned to the specified command bar control. For custom controls, use the OnAction property to specify the macro to run.

Syntax

expression.Execute

expression Required. An expression that returns a CommandBarControl, CommandBarButton, CommandBarPopup, or CommandBarComboBox object.

Example

This example checks the value of the combo box control on the custom command bar named "My Command Bar." If the value is "First," the example runs the macro specified by the OnAction property of the command bar control.

Set mycontrol = CommandBars("My Custom Bar").Controls(1)
With mycontrol
    If .List(.ListIndex) = "First" Then
        mycontrol.Execute
    End If
End With