Application.OnKey (Excel)

Runs a specified procedure when a particular key or key combination is pressed.

The Key argument can specify any single key combined with Alt, Ctrl, or Shift, or any combination of these keys. Each key is represented by one or more characters, such as a for the character a, or {ENTER} for the Enter key. To specify characters that aren't displayed when you press the corresponding key (for example: Enter or Tab), use the codes listed in the following table. Each code in the table represents one key on the keyboard.

OnKey (Key, Procedure)


Application.OnKey "^{+}", "InsertProc" 
Application.OnKey "+^{RIGHT}", "SpecialPrintProc"

Arguments

The following argument is required

Key (String) - A string indicating the key to be pressed.

Optional arguments

The following argument is optional

Procedure (String) - A string indicating the name of the procedure to be run. If Procedure is "" (empty text), nothing happens when Key is pressed. This form of OnKey changes the normal result of keystrokes in Microsoft Excel. If Procedure is omitted, Key reverts to its normal result in Microsoft Excel, and any special key assignments made with previous OnKey methods are cleared.