Application.DisplayAlerts 属性 (Excel)Application.DisplayAlerts property (Excel)

如果宏运行时 Microsoft Excel 显示特定的警告和消息,则为 TrueTrue if Microsoft Excel displays certain alerts and messages while a macro is running. 读取/写入 BooleanRead/write Boolean.

语法Syntax

expression.DisplayAlertsexpression.DisplayAlerts

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

说明Remarks

默认值为 TrueThe default value is True. 将此属性设置为 False 可在宏运行时禁止显示提示和警告消息;当出现需要用户应答的消息时,Microsoft Excel 将选择默认应答。Set this property to False to suppress prompts and alert messages while a macro is running; when a message requires a response, Microsoft Excel chooses the default response.

如果将此属性设置为 False,则 Excel 会在代码完成时将此属性设为 True,除非运行的是跨进程代码。If you set this property to False, Excel sets this property to True when the code is finished, unless you are running cross-process code.

备注

如果使用工作簿的 SaveAs 方法覆盖现有文件,则“确认另存为”对话框具有的默认响应为“”;如果将 DisplayAlerts 属性设置为 False,则 Excel 选择的响应为“”。When using the SaveAs method for workbooks to overwrite an existing file, the Confirm Save As dialog box has a default of No, while the Yes response is selected by Excel when the DisplayAlerts property is set to False. Yes 响应会覆盖现有文件。The Yes response overwrites the existing file.

如果使用工作簿的 SaveAs 方法以 Excel 5.0/95 文件格式保存包含 Visual Basic for Applications (VBA) 项目的工作簿,则“Microsoft Excel”对话框具有的默认响应为“”;如果将 DisplayAlerts 属性设置为 False,则 Excel 选择的响应为“取消”。When using the SaveAs method for workbooks to save a workbook that contains a Visual Basic for Applications (VBA) project in the Excel 5.0/95 file format, the Microsoft Excel dialog box has a default of Yes, while the Cancel response is selected by Excel when the DisplayAlerts property is set to False. 无法使用 Excel 5.0/95 文件格式保存包含 VBA 项目的工作簿。You cannot save a workbook that contains a VBA project by using the Excel 5.0/95 file format.

示例Example

本示例关闭工作簿 Book1.xls,但不提示用户保存所作更改。This example closes the Workbook Book1.xls and does not prompt the user to save changes. 不保存对 Book1.xls 所做的更改。Changes to Book1.xls are not saved.

Application.DisplayAlerts = False 
Workbooks("BOOK1.XLS").Close 
Application.DisplayAlerts = True

本示例禁止显示在启动连接到未运行的应用程序的 DDE 通道时一般会显示的消息。This example suppresses the message that otherwise appears when you initiate a DDE channel to an application that is not running.

Application.DisplayAlerts = False 
channelNumber = Application.DDEInitiate( _ 
 app:="WinWord", _ 
 topic:="C:\WINWORD\FORMLETR.DOC") 
Application.DisplayAlerts = True 
Application.DDEExecute channelNumber, "[FILEPRINT]" 
Application.DDETerminate channelNumber 
Application.DisplayAlerts = True

支持和反馈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.