Close Workbook Without Saving

Maintained on

When you retrieve data from another Excel file in VBA, the usual approach is to open it with the Workbooks.Open method and close it when you are done.

If you only need to read the file, there is no need to save it. Saving unnecessarily can also commit accidental changes to the data.

This page explains how to close a workbook without saving in VBA.

Answer: Pass SaveChanges:=False to the Close Method

Specifying False for the SaveChanges argument of Workbook.Close discards changes and closes the workbook without saving.

Close
Workbook.Close SaveChanges:=False

If you omit SaveChanges and the workbook has unsaved changes, Excel shows a “Do you want to save changes?” dialog and the macro stops. For automated processing, always specify SaveChanges explicitly.

SaveChanges valueBehavior
FalseClose without saving
TrueSave, then close (asks for a location for new workbooks)
OmittedShows a confirmation dialog if there are unsaved changes

Sample Code

Close the Active Workbook Without Saving

Close
ActiveWorkbook.Close SaveChanges:=False

ActiveWorkbook refers to the workbook in front when the macro runs. Use ThisWorkbook for the workbook that contains the macro itself. To avoid closing the wrong workbook, prefer the approach below of keeping a reference to a specific workbook.

Close a Specific Excel File Without Saving

Close
Dim wb As Workbook
Set wb = Workbooks.Open("C:\data\Book1.xlsx", ReadOnly:=True)

' ...do the necessary work...

wb.Close SaveChanges:=False

If you store the workbook in a variable when opening it with Workbooks.Open, you cannot close the wrong one by mistake. Opening it with ReadOnly:=True also lowers the risk of overwriting it when you only need to read.

Close All Workbooks Except the Macro’s Own

Close
Dim i As Long
For i = Workbooks.Count To 1 Step -1
    If Not Workbooks(i) Is ThisWorkbook Then
        Workbooks(i).Close SaveChanges:=False
    End If
Next i

Closing workbooks while iterating over Workbooks with For Each changes the collection size, so looping backwards is safer. ThisWorkbook is excluded because closing it would end the macro midway.

Changes are discarded and cannot be recovered. Make sure no other workbook contains unsaved work before running this.

Note: Showing or Suppressing the Confirmation Dialog

Instead of SaveChanges:=False, you can set the workbook’s Saved property to True so Excel treats it as already saved.

Mark
wb.Saved = True
wb.Close

You can also suppress the dialog with Application.DisplayAlerts = False, but this disables all other alerts too, so you must set it back to True afterward. To simply close a workbook, SaveChanges:=False is the simplest option.

Use Cases

  • Closing a read-only workbook opened temporarily during macro processing
  • Finishing without leaving behind temporary files generated by a macro
  • Reopening a test workbook repeatedly without keeping edits
#Excel #VBA