DocumentBeforeClose Event

Microsoft Publisher Visual Basic

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

object    A variable which references an object of type Application declared with events in a class module.

Doc Required. The document that's being closed.

Cancel Optional. False when the event occurs. If the event procedure sets this argument to True, the document doesn't close when the procedure is finished.

Remarks

To access the Application object events, declare an Application object variable in the General Declarations section of a code module. Then set the variable equal to the Application object for which you want to access events. For information about using events with the Microsoft Publisher Application object, see Using Events with the Application Object.

Example

This example prompts the user for a yes or no response before closing a document. This code must be placed in a class module, and an instance of the class must be correctly initialized, using an example similar to the SetPubApp routine below, in order to see this example work.

Private WithEvents PubApp As Application

Sub SetPubApp()
    Set PubApp = Publisher.Application
End Sub

Private Sub PubApp_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