Table of contents
Collapse the table of content
Expand the table of content

Application.EnableCancelKey Property (Project)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

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


expression. EnableCancelKey

expression A variable that represents an Application object.


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


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 

 If Err = 18 Then 
 MsgBox "Operation cancelled" 
 End If 

End Sub
© 2018 Microsoft