Skip to main content

Application.WorkbookBeforeSave event

Occurs before any open workbook is saved.

Syntax

expression.WorkbookBeforeSave (WbSaveAsUICancel)

expression A variable that represents an Application object.

Parameters

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

Nothing

Example

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

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>