确定哪些命令栏按钮开始在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