Name
Application.OnKey(Key
, [Procedure
])
Synopsis
Assigns a macro to run when a key is pressed. Can also be used to disable built-in Excel key combinations.
Argument |
Setting |
---|---|
|
The key combination to assign. The character codes are the same as for |
Procedure |
The name of the macro to run. Setting to |
The following code demonstrates how to reassign, disable, and restore a built-in key assignment:
Sub TestOnKey( ) ' Reassign Ctrl+C Application.OnKey "^c", "CopyMsg" ' Disable Ctrl+C 'Application.OnKey "^c", "" ' Restore Ctrl+C ' Application.OnKey "^c" End Sub Sub CopyMsg( ) MsgBox "You can't copy right now." End Sub
Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.