DocumentBeforeClose 事件

       

该事件在打开的文档关闭之前发生。

Private Sub object_DocumentBeforeClose(ByValDoc As Document, Cancel As Boolean)

object   在类模块的事件中声明的 Application 类型对象。有关使用 Application 对象的详细内容,请参阅使用 Application 对象的事件

Doc   将关闭的文档。

Cancel   如果为 False,则事件发生。 如果事件过程将该参数设为 True,则过程完成后不会文档关闭。

示例

本示例在文档关闭前,提示用户用“是”或“否”进行确认。 为了看到本例的执行效果,本例提供的代码必须保存在类模块中,而且该类中的实例必须正确地初始化;有关完成上述任务的指导,请参阅使用 Application 对象事件

Public WithEvents appWord as Word.Application

Private Sub appWord_DocumentBeforeClose _
        (ByVal Doc As Document, _
        Cancel As Boolean)

    Dim intResponse As Integer

    intResponse = MsgBox("Do you really " _
        & "want to close the document?", _
        vbYesNo)

    If intResponse = vbNo Then Cancel = True
End Sub