EnableCancelKey Property

Returns or sets how CTRL+BREAK is handled when a macro is running. Read/write Long.

PjEnableCancelKey

Constant
pjDisabled
PjErrorHandler
PjInterrupt

Example

This example shows how you can use the EnableCancelKey property to set up a custom cancellation 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

Applies to | Application Object