» 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:
- Flipping Properties: Generate Instant Cash Profits in Real Estate
- Financial Statement Analysis: A Practitioner's Guide, 3rd Edition
- Investing for Dummies, Third Edition
- Microsoft Office Xp: Advanced Concepts and Techniques: Word 2002, Excel 2002, Access 2002, Powerpoint 2002
- Investing in Real Estate, Fourth Edition
- How to Use Financial Statements: A Guide to Understanding the Numbers
No comments have been submitted.

