Microsoft ExcelでVBAを使用して、マクロを起動したコマンドバーボタンが決定し
マクロ自体に、マクロを開始した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