OnKey

Run a procedure when the specified key-combination is pressed.

Paste the following in a module:

Sub DemoOnKey()
	Application.OnKey "{TAB}", "Message"
End Sub

Sub Message()
    MsgBox "Hi"
End Sub

Run the procedure "DemoOnKey".

Ensure you are In a worksheet and press the "Tab" key. A message box saying "Hi" pops up.

To reset the "Tab" key to its normal setting, run the following procedure:

Sub DemoResetOnKey()
	Application.OnKey "{TAB}"
End Sub

To disable a key use this procedure:

Sub DemoDisableOnKey()
	Application.OnKey "{TAB}",""
End Sub

A full list of keys is shown in Excel's VBA Help file.

Published: 16-Dec-2003
Last edited: 05-Jun-2005 19:28