ERROR macro

Specifies what action to take if an error is encountered while a macro is running. Use ERROR to control whether Microsoft Excel error messages are displayed, or to run your own macro when an error is encountered.

Syntax

ERROR(enable_logical, macro_ref)

Enable_logical    is a logical value or number that selects or clears error-checking.

 

Macro_ref    specifies a macro to run if enable_logical is TRUE, 1, or 2 and an error is encountered. It can be either the name of the macro or a cell reference. If enable_logical is FALSE or 0, macro_ref is ignored.

Important   Both ERROR(FALSE) and ERROR(TRUE, macro_ref ) keep Microsoft Excel from displaying any messages at all, including the message asking whether to save changes when you close an unsaved workbook. If you want alert messages but not error messages to be displayed, use ERROR(2, macro_ref ).

Remarks

You can use GET.WORKSPACE to determine whether error-checking is on or off.

Examples

ERROR(FALSE) clears error-checking.

ERROR(TRUE, Recover) selects error-checking and runs the macro named Recover when an error is encountered.

The following macro runs the macro ForceMenus if an error occurs in the current macro:

=ERROR(TRUE, ForceMenus)

Related Functions

CANCEL.KEY   Disables macro interruption

LAST.ERROR   Returns the reference of the cell where the last error occurred

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

Return to index