Excel 2019 Bible

(singke) #1

Chapter 46: Working with Excel Events


46


By executing the following procedure, you cancel the OnKey events, and the keys return to
their normal functions:

Sub Cancel_OnKey()
Application.OnKey "{PgDn}"
Application.OnKey "{PgUp}"
End Sub

Contrary to what you may expect, using an empty string as the second argument for the OnKey method does not
cancel the OnKey event. Instead, it causes Excel to ignore the keystroke and do nothing. For example, the following
instruction tells Excel to ignore Alt+F4. (The percent sign represents the Alt key.)
Application.OnKey "%{F4}", ""

Free download pdf