vba Excel 事件被忽略/不再被捕获,即 Worksheet_Change 未在更改时输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5005018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel events ignored / no longer being caught i.e. Worksheet_Change not being entered on change
提问by FinancialRadDeveloper
I am working on a complex spreadsheet based solution. Occasionally a user will experience a problem where the events in the sheet seem to no longer be caught by Excel.
我正在研究基于复杂电子表格的解决方案。有时,用户会遇到 Excel 似乎不再捕获工作表中的事件的问题。
I cannot replicate this behaviour at present, but I have visted the PC in question and I can confirm that despite putting a breakpoint on the following none of them are being called :
我目前无法复制这种行为,但我已经访问了有问题的 PC,我可以确认尽管在以下位置设置了断点,但没有调用它们:
Worksheet_Activate()
Worksheet_Deactivate()
Worksheet_Change(ByVal Target As Range)
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Worksheet_Activate()
Worksheet_Deactivate()
Worksheet_Change(ByVal Target As Range)
Worksheet_BeforeDoubleClick(ByVal Target As Range,Cancel As Boolean)
This will of course be solved by the old classic 'have you tired turning it ( Excel ) on and off again' but I was wondering how this can happen, and how it may be prevented?
这当然可以通过古老的经典“你是否厌倦了再次打开和关闭它(Excel)”来解决,但我想知道这是如何发生的,以及如何预防?
I even put Stop / MsgBox "blah" into the methods to see if it was just the breakpoint in VBE but I didn't get anything for that.
我什至将 Stop / MsgBox "blah" 放入方法中,看看它是否只是 VBE 中的断点,但我没有得到任何东西。
So, anyone know why excel is no londer raising the events?
那么,有人知道为什么 excel 不再引发事件吗?
Cheers.
干杯。
FRD
FRD
回答by CaBieberach
Check your codes for:
检查您的代码:
Application.EnableEvents=False
If you turned it off, Excel wont turn it on again when your prodecure ends so be sure to set this parameter to TRUE at the end of your procedure.
如果您将其关闭,Excel 将不会在您的程序结束时再次打开它,因此请确保在您的程序结束时将此参数设置为 TRUE。
If you set it to False at the begining of your procedure and you stop your procedure before it is set to True again, then it stays off.
如果您在程序开始时将其设置为 False,并在它再次设置为 True 之前停止您的程序,则它保持关闭状态。
If your code crashes before reaching the Application.EnableEvents=True
line, then it will remain off also.
如果您的代码在到达该Application.EnableEvents=True
行之前崩溃,那么它也将保持关闭状态。
回答by Mahmoud Sayed
I've had this issue once on a sheet that doesn't contain any formulas... and that was the reason why Excel was not executing the Calculate Event!
我曾经在不包含任何公式的工作表上遇到过这个问题……这就是 Excel 不执行计算事件的原因!
Note.. the Calculate Event I needed to fire some code if a data-table was filtered.. so what I ended up doing was adding a small Sum() that pointed at a column in my table in a hidden cell and funny enough that had the calculate event to fire each time the sheet was filtered :)
注意..如果数据表被过滤,我需要触发一些代码的计算事件..所以我最终做的是添加一个小的 Sum() 指向我表中隐藏单元格中的一列并且足够有趣每次过滤工作表时都会触发计算事件:)