共用方式為


Application.ProtectedViewWindowBeforeClose Event (Excel)

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

Version Information

Version Added: Excel 2010

Syntax

expression .ProtectedViewWindowBeforeClose(Pvw, Reason, Cancel)

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

請參閱

概念

Application Object

Application Object Members