Excel vba - 禁用鼠标事件 [英] Excel vba - Disable Mouse Events
问题描述
我正在以手动的公式计算模式开发一个 Excel 2010 工作簿。
I'm developing an Excel 2010 workbook, in a manual formulas calculation mode.
>选项 - >公式 - >工作簿计算 - >手册
file -> options ->formulas ->Workbook calculation -> manual
但是,我想要一些菜单选项来导致重新计算工作簿。
However, I want some menu choices to cause recalculation of the workbook.
所以我使用以下代码:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Application.EnableEvents = False
If SOME_CONDITION
Application.Calculate
ActiveSheet.AutoFilter.ApplyFilter
End If
Application.EnableEvents = True
End Sub
问题是如果我在滚动鼠标中键,或在执行此功能时单击单元格,则计算在完成前突然终止,这是不可接受的。
The problem is that if I'm scrolling the middle mouse button, or clicking on a cell while this function is executed, the calculation is abruptly terminated before completion, which is unacceptable.
似乎行 Application.EnableEvents = False
不会阻止鼠标事件触发,我不能找到任何可以防止这个错误的替代方案。
It seems that the line Application.EnableEvents=False
doesn't prevent the mouse events from being fired, and I wasn't able to find any alternative which will prevent this bug.
所以我需要的是在计算过程中阻止所有事件的方式,或以某种方式阻止发生事件破坏计算(就像在工作簿公式计算不是手动的时候)。
So what I need is either a way to block all events during the calculation, or somehow prevent the fired events from disrupting the calculation (as it is when the workbook formulas calculation is not manual).
非常感谢你的帮助!
谢谢。
Matan。
推荐答案
尝试这样:
Application.Interactive = False
宏正在运行。完成后将其恢复为真。
While the macro is running. Turn it back to true when done.
这篇关于Excel vba - 禁用鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!