Skip to main content

Application.ProtectedViewWindowBeforeClose event

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

Syntax

expression.ProtectedViewWindowBeforeClose (PvwReasonCancel)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
Pvw Required ProtectedViewWindow An object that represents the Protected View window that is closed.
Reason Required XlProtectedViewCloseReason A constant 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.

Return value

Nothing

Example

The following code example prompts the user for a yes or no response before closing the Protected View window. This code must be placed in a class module, and an instance of that class must be correctly initialized.

For more information about how to use event procedures with the Application object, see Using events with the Application object.

Private Sub App_ProtectedViewWindowBeforeClose(ByVal Pvw As ProtectedViewWindow, _
    Reason As XlProtectedViewCloseReason, Cancel As Boolean)
    a = MsgBox("Do you really want to close the Protected View window?", vbYesNo)
    If a = vbNo Then Cancel = True
End Sub

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>