This documentation is archived and is not being maintained.

Workbook.BeforeSave Event

Office 2007
Occurs before the workbook is saved.

Syntax

expression.BeforeSave(SaveAsUI, Cancel)

expression   A variable that represents a Workbook object.

Parameters

NameRequired/OptionalData TypeDescription
SaveAsUIRequiredBooleanTrue if the Save As dialog box will be displayed.
CancelRequiredBooleanFalse when the event occurs. If the event procedure sets this argument to True, the workbook isn't saved when the procedure is finished.

Return Value
Nothing

Example

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

Visual Basic for Applications
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
        Cancel as Boolean)
    a = MsgBox("Do you really want to save the workbook?", vbYesNo)
    If a = vbNo Then Cancel = True
End Sub



Show: