Determinar qué botón CommandBar que se inició una macro utilizando VBA en Microsoft Excel
Deje que las macros determinen qué botón de CommandBar las inició.
Si adjunta la macro siguiente a varios botones de CommandBar, el cuadro de mensaje mostrará diferentes contenidos:
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