Application.WorkbookBeforeSave Event (Excel)

Occurs before any open workbook is saved.

NOTE: In Office 365, Excel supports AutoSave, which enables the user's edits to be saved automatically and continuously. Following the guidance in this article will ensure that running code in response to the WorkbookBeforeSave event will function as intended when AutoSave is enabled.


expression. WorkbookBeforeSave( _Wb_ , _SaveAsUI_ , _Cancel_ )

expression A variable that represents an [Application](./Excel.Application(Graph property).md) object.


Name Required/Optional Data Type Description
Wb Required Workbook The workbook.
SaveAsUI Required Boolean True if the Save As dialog box will be displayed due to changes made that need to be saved in the workbook.
Cancel Required Boolean False 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



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

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _ 
 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

See also

Application Object