Skip to main content

Workbook.BeforeClose event

Occurs before the workbook closes. If the workbook has been changed, this event occurs before the user is asked to save changes.


expression.BeforeClose (Cancel)

expression A variable that represents a Workbook object.


Name Required/Optional Data type Description
Cancel Required Boolean False when the event occurs. If the event procedure sets this argument to True, the close operation stops and the workbook is left open.

Return value



This example always saves the workbook if it has been changed.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If Me.Saved = False Then Me.Save
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>