Excel 2007 VBA工作簿关闭然后重新打开 [英] Excel 2007 VBA Workbook closing then reopening

查看:737
本文介绍了Excel 2007 VBA工作簿关闭然后重新打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在2003年,工作簿就会结束。但现在相同的代码是重新打开工作簿。之后有一些行,然后是次级。当子结束时,即使没有打开任何工作簿的代码, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆