Application.ProtectedViewWindowBeforeClose event (Excel)
Occurs immediately before a Protected View window or a workbook in a Protected View window closes.
expression.ProtectedViewWindowBeforeClose (Pvw, Reason, Cancel)
expression A variable that represents an Application object.
|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.|
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
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.