Application.EnableCancelKey property (Project)

Gets or sets a value that controls how the CTRL + BREAK key combination is handled when a macro is running. Read/write PjEnableCancelKey.

Syntax

expression. EnableCancelKey

expression A variable that represents an Application object.

Remarks

The EnableCancelKey property can be one of the following PjEnableCancelKey constants: pjDisabled, pjErrorHandler, or pjInterrupt.

Example

The following example shows how you can use the EnableCancelKey property to create a custom cancellation error handler.

Sub CancelOperation() 
 Dim X As Long 
 
 On Error GoTo handleCancel 
 
 Application.EnableCancelKey = pjErrorHandler 
 MsgBox "This may take a long time; press CTRL+BREAK to cancel." 
 
 For X = 1 To 300000000 
 ' Do something here. 
 Next X 
 
handleCancel: 
 If Err = 18 Then 
 MsgBox "Operation cancelled" 
 End If 
 
End Sub

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.