» 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
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
Book Store:
Recommended Books:
- Millionaire Real Estate Mentor : The Secrets of Financial Freedom through Real Estate Investing
- Microsoft Office Xp: Advanced Concepts and Techniques: Word 2002, Excel 2002, Access 2002, Powerpoint 2002
- Absolute Beginner's Guide to Microsoft Office Excel 2003
- Yes, You Can Time the Market!
- Analyzing Markets, Products, and Marketing Plans
- How to Pay Zero Taxes (Annual)
No comments have been submitted.

