Name

commandbars.ActionControl

Synopsis

Returns the CommandBarControl object that ran the current procedure. If the current procedure was not run by a CommandBarControl, returns Nothing. The following code displays a message in the Immediate window when Sample2 is called from a menu item or toolbar button:

Sub Sample2( )
    Dim cbc As CommandBarButton
    MsgBox "Sample2"
    Set cbc = Application.CommandBars.ActionControl
    If Not cbc Is Nothing Then _
     Debug.Print "Sample2 called by: " & cbc.Tag
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.