DocumentBeforePrint 事件

       

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

Private Sub object_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)

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

Doc   将打印的文档。

Cancel   如果为 False,则事件发生。如果事件过程将此参数设为 True,则过程完成后将不打印文档。

示例

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

Public WithEvents appWord as Word.Application

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

    Dim intResponse As Integer

    intResponse = MsgBox("Have you checked the " _
        & "printer for letterhead?", _
        vbYesNo)

    If intResponse = vbNo Then Cancel = True
End Sub