Cancel property (Microsoft Forms)

Returns or sets a value indicating whether a command button is the Cancel button on a form.

Syntax

object.Cancel [= Boolean ]

The Cancel property syntax has these parts:

Part Description
object Required. A valid object.
Boolean Optional. Whether the object is the Cancel button.

Settings

The settings for Boolean are:

Value Description
True The CommandButton is the Cancel button.
False The CommandButton is not the Cancel button (default).

Remarks

A CommandButton or an object that acts like a command button can be designated as the default command button. For OLE container controls (Windows only), the Cancel property is provided only for those objects that specifically behave as command buttons.

Only one CommandButton on a form can be the Cancel button. Setting Cancel to True for one command button automatically sets it to False for all other objects on the form. When a CommandButton's Cancel property is set to True and the form is the active form, the user can choose the command button by clicking it, pressing Esc, or pressing Enter when the button has the focus.

A typical use of Cancel is to give the user the option of canceling uncommitted changes and returning the form to its previous state.

You should consider making the Cancel button the default button for forms that support operations that can't be undone (such as delete). To do this, set both Cancel and the Default property to True.

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.