» 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
CATEGORY - Menus, Toolbars, Status bar in VBA
VERSION - All Microsoft Excel Versions
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
Book Store:
Recommended Books:
- The Financial Numbers Game: Detecting Creative Accounting Practices
- Keys to Reading an Annual Report (Barron's Business Keys)
- Marketing Plans That Work, Targeting Growth and Profitability
- Financial Risk Manager Handbook, Second Edition
- Now, Discover Your Strengths
- H&R Block's Just Plain Smart(tm) Tax Planning Advisor: A year-round approach to lowering your taxes this year, next year and beyond
No comments have been submitted.

