This documentation is archived and is not being maintained.

Application.WorkbookBeforeClose Event

Office 2007
Occurs immediately before any open workbook closes.

Syntax

expression.WorkbookBeforeClose(Wb, Cancel)

expression   A variable that represents an Application object.

Parameters

NameRequired/OptionalData TypeDescription
WbRequiredWorkbookThe workbook that's being closed
CancelRequiredBooleanFalse 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
Nothing

Example

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

Visual Basic for Applications
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



Show: