EnableCancelKey 属性(Project)Application.EnableCancelKey property (Project)

获取或设置运行宏时处理控制方式 CTRL + BREAK 键组合的值。Gets or sets a value that controls how the CTRL + BREAK key combination is handled when a macro is running. 读/写PjEnableCancelKeyRead/write PjEnableCancelKey.

语法Syntax

expressionexpression. EnableCancelKey

expression:表示 Application 对象的变量。expression A variable that represents an Application object.

备注Remarks

EnableCancelKey 属性可以是下面的 PjEnableCancelKey 常量之一: pjDisabledpjErrorHandlerpjInterruptThe EnableCancelKey property can be one of the following PjEnableCancelKey constants: pjDisabled, pjErrorHandler, or pjInterrupt.

示例Example

下面的示例演示如何使用 EnableCancelKey 属性来创建自定义取消错误处理程序。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

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.