Application.ProtectedViewWindowBeforeClose event (Word)

Occurs immediately before a Protected View window or a document in a Protected View window closes.

Syntax

expression. ProtectedViewWindowBeforeClose( _PvWindow_ , _CloseReason_ , _Cancel_ )

expression An expression that returns an Application object.

Parameters

Name Required/Optional Data type Description
PvWindow Required ProtectedViewWindow The Protected View window that is closed.
CloseReason Required [INT] A constant in the WdProtectedViewCloseReason enumeration that specifies the reason the Protected View window is closed.
Cancel Required Boolean False when the event occurs. If the event procedure sets this argument to True, the window does not close when the procedure is finished.

Note

If the ProtectedViewWindowsBeforeClose event is called as part of the ProtectedView.Edit method, setting Cancel to True produces no action.

|

Example

The following code example prompts the user for a yes or no response before closing any document. This code must be placed in a class module, and an instance of the class must be correctly initialized to see this example work. For more information about how to do this, see Using events with the Application object.

The following code example assumes that you have declared an application variable called "App" in your general declarations and have set the variable equal to the Word Application object.

Private Sub App_ProtectedViewWindowBeforeClose(ByVal PvWindow As ProtectedViewWindow, ByVal CloseReason As Long, 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

See also

Application Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.