VBA 捕获“计算工作表(shift+f9)”和“计算工作簿”事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8327329/
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
VBA catch the "calculate sheet (shift+f9)" and "calculate workbook" events
提问by BuZz
I don't know if this is trivial or actually hacky to do : is it possible to catch the "calculate sheet (shift+f9)" and "calculate workbook" events in VBA ?
我不知道这是微不足道的还是实际上很困难:是否可以在 VBA 中捕获“计算表 (shift+f9)”和“计算工作簿”事件?
I want to hide some processes that manipulate a few thousands lines, to just display some key values. I am calculating a distribution, the thousands lines, and want to just output the percentiles and some stats, as well as the graph instead of all these lines. At the moment I was thinking of a classic macro button, but my users are keener on the F9 way of life..
我想隐藏一些操作几千行的进程,只显示一些关键值。我正在计算分布,数千行,并且只想输出百分位数和一些统计数据,以及图表而不是所有这些行。目前我正在考虑经典的宏按钮,但我的用户更热衷于 F9 的生活方式。
Do you think I'm pointing towards something interesting with what I suggest in the title ?
你认为我在标题中的建议是指向一些有趣的东西吗?
回答by Tony Dallimore
The OnKey command allows you to disable any key or key combination or make that key do something different.
OnKey 命令允许您禁用任何键或键组合或使该键执行不同的操作。
This macro will be executed automatically when the workbook containing it is opened.
当打开包含它的工作簿时,将自动执行此宏。
Sub Auto_Open()
Application.OnKey "{F9}", "HandleF9"
Application.OnKey "^{F9}", "HandleCtrlF9"
Application.OnKey "+{F9}", "HandleShiftF9"
End Sub
The following routines will be executed instead of Calculate.
将执行以下例程而不是计算。
Sub HandleF9()
Debug.Print "F9 clicked"
End Sub
Sub HandleCtrlF9()
Debug.Print "Ctrl+F9 clicked"
End Sub
Sub HandleShiftF9()
Debug.Print "Shift+F9 clicked"
End Sub
See OnKey help for more information.
有关详细信息,请参阅 OnKey 帮助。