VBA catch the “calculate sheet (shift+f9)” and “calculate workbook” events

我只是一个虾纸丫 提交于 2020-01-13 19:09:23

问题


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 ?

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..

Do you think I'm pointing towards something interesting with what I suggest in the title ?


回答1:


The OnKey command allows you to disable any key or key combination or make that key do something different.

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.



来源:https://stackoverflow.com/questions/8327329/vba-catch-the-calculate-sheet-shiftf9-and-calculate-workbook-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!