Xác định nút CommandBar nào bắt đầu macro bằng VBA trong Microsoft Excel
Hãy để các macro tự xác định nút CommandBar nào đã khởi động chúng.
Nếu bạn đính kèm macro bên dưới vào nhiều nút CommandBar, hộp thư sẽ hiển thị các nội dung khác nhau:
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