Share via


Application.EnableCancelKey Property

Project Developer Reference

Returns or sets how CTRL+BREAK is handled when a macro is running. Read/write Long. Can be one of the PjEnableCancelKey constants.

Syntax

expression.EnableCancelKey

expression   A variable that represents an Application object.

Return Value
PjEnableCancelKey

Example

This example shows how you can use the EnableCancelKey property to set up a custom cancellation handler.

Visual Basic for Applications
  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

See Also