매크로가 시작된 CommandBar 단추를 결정하도록합니다.

아래 매크로를 여러 CommandBar 버튼에 첨부하면 메시지 상자에 다른 내용이 표시됩니다.

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