Determine which CommandBar button that started a macro

 2000-07-31    Commandbars    0    52

Let the macros themselves determine which CommandBar button that started them. If you attach the macro below to multiple CommandBar buttons, the messagebox will display different contents:

Sub DummyMacro()
    If Application.CommandBars.ActionControl Is Nothing Then 
    ' the macro was not started from a commandbar button
        MsgBox "This could be your macro running!", vbInformation, _
            "This macro was not started from a CommandBar button"
    Else ' the macro was started from a commandbar button
        MsgBox "This could be your macro running!", vbInformation, _
            "This macro was started from this CommandBar button: " & _ 
            Application.CommandBars.ActionControl.Caption
    End If
End Sub


Leave a comment:

Your comment will only be published after it has been moderated and found spam free.
Your e-mail address will only be used to display your Gravatar.