Skip to main content

Application.WorkbookBeforeClose event

Occurs immediately before any open workbook closes.


expression.WorkbookBeforeClose (WbCancel)

expression A variable that represents an Application object.


Name Required/Optional Data type Description
Wb Required Workbook The workbook that's being closed.
Cancel Required Boolean False when the event occurs. If the event procedure sets this argument to True, the workbook doesn't close when the procedure is finished.

Return value



This example prompts the user for a yes or no response before closing any workbook.

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

Private Sub App_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
    a = MsgBox("Do you really want to close the workbook?", 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>