[英]Excel VBA On Open Macro Runs for other Workbooks
I have a very simple Workbook_Open procedure that hides the ribbon. 我有一个非常简单的Workbook_Open过程,它会隐藏功能区。 Problem is if I have that workbook with the macro open and then open a another different Excel workbook the procedure runs for that workbook and hides its ribbon as well (even for Excel 2003 files)
问题是,如果我打开了该工作簿并打开了另一个宏,然后又打开了另一个不同的Excel工作簿,则该程序将为该工作簿运行,并隐藏其功能区(即使对于Excel 2003文件也是如此)
Any ideas on what is going on? 有什么想法吗? Below is the procedure
以下是程序
Private Sub Workbook_Open()
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
End Sub
Answer stolen from this mrexcel topic . 回答从这个mrexcel主题中偷来的东西 。
You need to add Private Sub Workbook_Deactivate
and Private Sub Workbook_Activate
to ThisWorkbook as well: 您还需要将
Private Sub Workbook_Deactivate
和Private Sub Workbook_Activate
到ThisWorkbook中:
Private Sub Workbook_Activate()
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
End Sub
Private Sub Workbook_Deactivate()
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
End Sub
When the new workbook is opened, the previous one will be deactivated, and show the ribbon for the new workbook. 打开新工作簿时,将停用上一个工作簿,并显示新工作簿的功能区。
Tested working on Excel 2013 经过测试可在Excel 2013上使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.