Excel 2007 VBA工作簿关闭然后重新打开 [英] Excel 2007 VBA Workbook closing then reopening
问题描述
workbook_open
事件也会被关闭。调试器几乎没用,如果我一步一步地执行所有的操作就不会再现错误,实际上当我使用调试器的时候,一切正常。 我使用
ActiveWorkbook.Close False
关闭工作簿
非常感谢。
Application.OnTime EarliestTime:= Now(),Procedure:=Name时间表:= False
,否则ontime事件将被执行。
如果事件在beforeclose被调用之前未被取消,则工作簿将关闭,然后重新打开以运行计划的ontime事件(因为工作簿被简单地打开,以至于没有机会运行在我需要关闭它之前)。
In 2003 the workbook would just close. But now the same code is re-opening the workbook. There are some lines afterwards and then the sub ends. When the sub ends, the workbook_open
event gets fired for the closed workbook, even though there is no code that opens any workbooks. The debugger is almost useless, it is not reproducing the bug if I execute everything step by step, in fact everything works fine when I use the debugger.
I use
ActiveWorkbook.Close False
For closing the workbook (from an add-in).
Help much appreciated.
Figured out how to get both. Workbook_beforeclose cancels the scheduled ontime event by calling:
Application.OnTime EarliestTime:=Now(), Procedure:="Name", Schedule:=False
but otherwise the ontime event gets executed.
If the event does not get cancelled before beforeclose is called, the workbook will close then re-open to run the scheduled ontime event (because the workbook is opened so briefly that ontime doesn't get a chance to run before I need to close it).
这篇关于Excel 2007 VBA工作簿关闭然后重新打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!