CANCEL.KEY

Macro Sheets Only

Disables macro interruption, or specifies a macro to run when a macro is interrupted. Use CANCEL.KEY to control what happens when a macro is interrupted.

Syntax

CANCEL.KEY(enable, macro_ref)

Enable specifies whether the macro can be interrupted by pressing ESC in Microsoft Excel for Windows or ESC or COMMAND+PERIOD in Microsoft Excel for the Macintosh.

If enable is Then

FALSE Pressing ESC or COMMAND+PERIOD does not interrupt a macro

TRUE and macro_ref is omitted Pressing ESC or COMMAND+PERIOD interrupts a macro

TRUE and macro_ref is specified Macro_ref runs when ESC or COMMAND+PERIOD is pressed

Macro_ref is a reference to a macro, as a cell reference or a name, that runs when enable is TRUE and ESC or COMMAND+PERIOD is pressed.

Remarks

Examples

The following macro formula prevents the macro from being interrupted by pressing ESC or COMMAND+PERIOD:


CANCEL.KEY(FALSE)

The following macro formula reactivates ESC or COMMAND+PERIOD to cancel macro execution:


CANCEL.KEY(TRUE)

The following line in a macro runs CheckCancel when ESC or COMMAND+PERIOD is pressed:


CANCEL.KEY(TRUE, CheckCancel)

Related Functions

ERROR Specifies an action to take if an error occurs while a macro is running

ON.KEY Runs a macro when a specified key is pressed

ON.TIME Runs a macro at a specified time

List of Customizing Functions