» 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:
- Microsoft Windows XP Registry Guide
- The 22 Immutable Laws of Branding
- The Financial Numbers Game: Detecting Creative Accounting Practices
- Real Estate Finance and Investments (Real Estate Finance and Investments, 11th Ed)
- Special Edition Using Microsoft Word 2002
- Microsoft Office XP Introductory Concepts and Techniques
No comments have been submitted.


