如何阻止Excel在Workbook_BeforeSave之前触发Worksheet_Change? [英] How to stop Excel from firing Worksheet_Change before Workbook_BeforeSave?

查看:199
本文介绍了如何阻止Excel在Workbook_BeforeSave之前触发Worksheet_Change?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:已解决问题我们的同事在 Workbook_BeforeSave()中更改单元格,而不会禁用事件,因此触发 Worksheet_Change()。是的,傻,但至少这是我们的错,不是Excel的

Update: Issue Resolved A colleague of mine was changing a cell during Workbook_BeforeSave() without disabling events, therefore triggering Worksheet_Change(). Yes, silly, but at least it's our fault, not Excel's

我注意到,每当我在Excel中按Ctrl + S, Worksheet_Change() Workbook_BeforeSave()之前被触发。是否可以使用VBA代码来抑制此行为,但不抑制所有事件(即没有 Application.EnableEvents = false )?

I've noticed that whenever I hit Ctrl+S in Excel, the Worksheet_Change() is fired before Workbook_BeforeSave(). Is it possible to supress this behaviour using VBA code, but without supressing all events (i.e. without Application.EnableEvents = false)?

无论我在做什么,都会发生这种情况。我已经阅读了有关ComboBoxes类似问题的人,但是我并没有编辑ComboBoxes,而是在保存前总是保存 Worksheet_Change()

This happens regardless of what I'm doing. I've read about someone having a similar issue with ComboBoxes, but I'm not editing ComboBoxes, yet Worksheet_Change() fires always before saving.

任何想法?当我保存文档时,我只想知道如何绕过 Worksheet_Change()中的一些代码,因为该代码只有在用户实际更改时才被执行某些东西,而不是保存工作簿时。保存不会改变...

Any ideas? I'm only trying to figure out how to bypass some code inside Worksheet_Change() when the document is saved, because that code is only supposed to be executed when the user actually changes something, not when the workbook is saved. Saving is by no means changing...

推荐答案

这是我们身边的一个编码错误:

It was a coding mistake on our side:

我的同事在Workbook_BeforeSave()中更改一个单元格,而不会禁用事件,因此触发Worksheet_Change()。

A colleague of mine was changing a cell during Workbook_BeforeSave() without disabling events, therefore triggering Worksheet_Change().

修复很容易。在Workbook_BeforeSave()中:

The fix was easy. In Workbook_BeforeSave():

Application.EnableEvents = False
' Some final changes
Application.EnableEvents = True

那就是:)

这篇关于如何阻止Excel在Workbook_BeforeSave之前触发Worksheet_Change?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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