ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

 

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Determine which CommandBar button that started a macro

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

 

Document last updated 2000-07-31 12:47:00

 

 
Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address