BeforeClose Event
TOC
Collapse the table of content
Expand the table of content

Workbook.BeforeClose Event (Excel)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

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.

Parameters

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

Nothing

This example always saves the workbook if it's been changed.

Private Sub Workbook_BeforeClose(Cancel as Boolean) 
 If Me.Saved = False Then Me.Save 
End Sub
Show:
© 2016 Microsoft