我已将宏作为命令添加到特定工作簿。但新工作簿将显示这些命令,如果我单击它,它只会打开上一个工作簿。我宁愿它们不出现在新工作簿的命令栏中。这可能吗?
答案1
将此代码添加到 ThisWorkbook 模块:
Private Sub Workbook_WindowActivate(ByVal Wn As Excel.Window)
'This runs on switching to the workbook from another Workbook
CommandBars("MyToolbar").Visible = True
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
'This runs on switching away from the workbook to another Workbook
CommandBars("MyToolbar").Visible = False
End Sub