Excel 控件事件在应用程序关闭时触发
我有一个 Excel 工作簿,工作表上有 ActiveX 控件(而不是用户窗体上!)。当我关闭工作簿(不关闭 Excel)时,一切正常,但是当我完全关闭 Excel 时,它会触发工作表上 ActiveX 组合框的更改事件。这会产生错误,因为 Excel 似乎已经通过删除控件进行了一些清理。
我该如何绕过或解决这个问题?这些事件不应首先触发,因为关闭时不会更改任何值。
I've an Excel-workbook with ActiveX controls on worksheets (not on Userform!). When I close the workbook (without closing Excel) everything works well, but when I close Excel entirely it triggers Change events of ActiveX Comboboxes on the worksheets. This creates errors because it seems that Excel has done some cleaning already by removing controls.
How can I bypass or solve this? These events shouldn't trigger in the first place because no values are changed on close.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不了解 ActiveX 控件的设置方式,我无法告诉您为什么会触发它们的更改事件。但是,假设工作簿的 BeforeClose 事件在 ActiveX 更改事件之前触发,您可以添加一个全局变量来跟踪工作簿何时关闭。
在代码模块中:
在 ThisWorkbook 中:
如果不关闭工作簿,则仅运行更改事件。
Without seeing how your ActiveX controls are setup I can't tell you why their change events are firing. However, assuming the workbook's BeforeClose event fires before the ActiveX change events, you can add a global variable to track when the workbook is closing.
In a code module:
In ThisWorkbook:
Then only run the change events if not closing the workbook.
将此子项插入模块中,并使用它来保存和关闭工作簿和 Excel。首先禁用事件,这应该可以防止出现问题。
您还可以检查“ThisWorkbook”中的代码;也许
Workbook_BeforeClose
中有一些东西。Insert this sub into a module and use it to save and close both the workbook and Excel. Events are disabled first which should prevent the problem.
You also might check to see what code is in "ThisWorkbook"; maybe there is something in
Workbook_BeforeClose
.