|  

» Determine which CommandBar button that started a macro using VBA in Microsoft Excel

VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
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




Rate This Tip
12 34 5
Rating: 3.46     Views: 15411
No comments have been submitted.
Click here to post comment
For Registered Users
Name
Comment Title
Comments