Workbook_Open()不会执行Excel 2011 [英] Workbook_Open() won't execute Excel 2011
问题描述
使用Excel 2011(应与Excel 2010相同)
代码位于Excel中的ThisWorkbook模块
事件已启用
启用宏
我似乎无法获得code> Workbook_Open()或 Workbook_BeforeClose()
执行。我已经读了很多关于这个问题的帖子,但没有解决方案这是一些简单的测试代码,应该执行,但不执行。任何帮助将不胜感激。
Private Sub Workbook_Open()
ActiveSheet.Range(BL4)。 =打开正在工作
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next',以防菜单项已被删除
ActiveSheet.Range(BL5)。Value =关闭工作
End Sub
首先确保你把它放在正确的位置并启用宏。
然后,尝试将此行添加到workbook_open方法中:
MsgBoxHELLO
你看到msg框吗?你可以选择单元格看起来有点奇怪
另外,我想你需要使用.xlsm文件不是.xlsx(虽然不确定那个) p>
最后,如果一个插件调用类似这样的行,它可能会导致你的事件不触发。
Application.EnableEvents = False
所以确保你已经测试了
Using Excel 2011 (should be same as Excel 2010)
Code is under the "ThisWorkbook" module in Excel
Events are enabled
Macros are enabled
I can't seem to get either Workbook_Open()
or Workbook_BeforeClose()
to execute. I've read numerous posts on the subject but no solution. Here is some simple test code that should execute but doesn't. Any help would be greatly appreciated.
Private Sub Workbook_Open()
ActiveSheet.Range("BL4").Value = "Open is working"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next 'in case the menu item has already been deleted
ActiveSheet.Range("BL5").Value = "Close is working"
End Sub
First make sure you have put this in this in the right place and have macros enabled.
Then, try adding this line to the workbook_open method:
MsgBox "HELLO"
Do you see the msg box? You're choice of cell looks a bit strange
Also, I think you need to use a .xlsm file not .xlsx (Although not sure on that one)
FInally, if a plugin calls something like this line, it could cause your events not to fire..
Application.EnableEvents = False
So make sure you have tested it with no other sheets or addins open.
这篇关于Workbook_Open()不会执行Excel 2011的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!