CommandBarButton.OnAction Property (Office)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Gets or sets the name of a Visual Basic procedure that will run when the user clicks or changes the value of a CommandBarButton control. Read/write.

Note Note

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, search Help for the keyword "ribbon."

expression .OnAction

expression A variable that represents a CommandBarButton object.

Return Value


The container application determines whether the value is a valid macro name.

This example adds a command bar control to the command bar named "Custom". The COM add in named "FinanceAddIn" will run each time the control is clicked.

Set myBar = CommandBars("Custom") 
Set myControl = myBar.Controls _ 
With myControl 
    .FaceId = 2 
    .OnAction = "!<FinanceAddIn>" 
End With 
myBar.Visible = True