VBA Close Workbook Without Saving: Safe Methods

VBA & macros · Updated November 18, 2026

To close a workbook and discard its unsaved changes in Excel VBA, call its Close method with SaveChanges:=False, for example: wb.Close SaveChanges:=False. This explicitly tells Excel not to save that workbook’s changes; it is usually clearer and safer than suppressing Excel’s save prompt.

What SaveChanges:=False does

Excel’s VBA Workbook.Close method closes a particular workbook. Its SaveChanges argument controls whether Excel saves that workbook as it closes: True saves changes, while False discards changes made since the last save. If you omit the argument, Excel may ask whether to save when the workbook has unsaved changes.

The setting applies to the workbook you close, not to every workbook open in the Excel session. It also does not undo edits while the workbook remains open. Once the workbook is closed without saving, its unsaved changes are gone. Excel’s Undo command cannot bring them back, so make a copy first if there is any chance you will need the changes.

For example, if a macro changes cell values, formatting, or worksheet structure and then closes the target workbook with SaveChanges:=False, those changes are discarded. Changes saved earlier during that session remain in the saved file; the argument does not roll back previous saves.

Choose the right workbook reference

The key practical decision is which workbook object to close. A macro can refer to a workbook by its name in the Workbooks collection, by ActiveWorkbook, or by ThisWorkbook. Those references are not interchangeable:

  • Workbooks("Report.xlsx") identifies the open workbook by its filename, including its extension. Use this when you know the exact workbook to close.
  • ActiveWorkbook means the workbook currently in front. It can change when a user clicks another workbook or when a macro activates a different one, so it can target the wrong file.
  • ThisWorkbook means the workbook that contains the VBA code. It is appropriate when that workbook itself should close, but not necessarily when the macro is stored in a different file.

If you are closing a workbook that a macro has just opened, keep the returned workbook object in a variable. That avoids relying on which workbook happens to be active later.

Close a named workbook without saving

This example closes a workbook that is already open. Before running a macro that discards changes, save a separate copy of the workbook if you may need its current contents. VBA macros cannot be undone with Ctrl+Z.

Sub CloseNamedWorkbookWithoutSaving()
    Dim wb As Workbook

    ' Set this to the exact name shown in the Excel title bar.
    Set wb = Workbooks("Report.xlsx")

    ' Discard unsaved changes in this workbook and close it.
    wb.Close SaveChanges:=False
End Sub

Replace Report.xlsx with the actual open workbook name. A workbook saved as a macro-enabled file might instead be named Report.xlsm. If no open workbook has the supplied name, VBA raises an error. In a larger automation routine, you can check whether the workbook is open before attempting to close it rather than assuming it is present.

For a workbook your macro has opened, assigning the result of Workbooks.Open is a reliable way to retain the target:

Sub OpenAndDiscardWorkbookChanges()
    Dim wb As Workbook

    ' Save a separate copy first if the file contains anything valuable.
    Set wb = Workbooks.Open(Filename:="C:\Reports\Draft.xlsx")

    ' Close this specific workbook without saving changes made in this session.
    wb.Close SaveChanges:=False
End Sub

In this example, the file is opened and then immediately closed, so it mainly demonstrates how to keep a precise object reference. In a real procedure, put the work you intend to do between the open and close lines. The close argument will discard those unsaved edits.

Close the workbook that contains the macro

When the workbook containing the code should close itself, use ThisWorkbook:

Sub CloseThisWorkbookWithoutSaving()
    ' Save a copy before running if this workbook has changes to preserve.
    ThisWorkbook.Close SaveChanges:=False
End Sub

Be careful about what happens next: when Excel closes the workbook that hosts the running VBA project, the project is unloaded, so you should not depend on code after the close call to finish essential work. If a macro needs to close another workbook and then continue, store the macro in a different open workbook, an add-in, or Personal Macro Workbook, and close the target by its object reference.

For example, code in Personal Macro Workbook can close an ordinary report workbook while the macro’s own VBA project remains open. Conversely, if the macro is inside the report workbook, closing that report is a poor way to trigger a long sequence of follow-up actions.

Why an explicit argument is better than hiding prompts

Excel can suppress many dialog boxes through Application.DisplayAlerts = False, but that setting changes behavior more broadly than a single workbook close. Excel may choose a default response to a dialog, and other operations in the procedure may also be affected. It is not a precise replacement for specifying how one workbook should close.

Prefer wb.Close SaveChanges:=False when your intention is specifically to discard changes to wb. If you temporarily turn off alerts for a separate reason, restore the previous setting even if an error occurs; otherwise later actions in the same Excel session may run without prompts. Do not turn alerts off just to avoid deciding whether a particular file should be saved.

Also distinguish a save prompt from other messages. The close argument controls saving the specified workbook, but it does not necessarily eliminate unrelated prompts, such as a message from another workbook or an application-level warning. Address those separately rather than assuming one setting handles every dialog.

Common mistakes and troubleshooting

  • Closing the active workbook by accident: A macro that uses ActiveWorkbook.Close can close the wrong file if focus changed. Capture the intended workbook in a variable or identify it by name.
  • Using the wrong filename: The name in the Workbooks collection includes the extension. Check whether the file is named .xlsx, .xlsm, or another supported workbook type.
  • Expecting the change to be reversible: Closing without saving discards unsaved edits. Ctrl+Z does not reopen the workbook or restore those edits.
  • Expecting the macro to continue after closing its host: A procedure should not rely on statements after it closes the workbook containing its VBA project. Move the controlling code elsewhere if it must continue.
  • Confusing read-only status with the close argument: A workbook opened read-only generally cannot save changes back to the original file, but that is a separate condition. SaveChanges:=False still clearly states that the workbook should close without saving.

If VBA stops with an error on the Workbooks line, confirm that the file is already open and that the name matches exactly. If an unexpected workbook closes, inspect how the macro sets or changes the active workbook and replace an ambiguous active reference with a stored object variable.

Windows, Mac, and Excel for the web

The Workbook.Close SaveChanges:=False VBA syntax is used in desktop Excel for Microsoft 365 on Windows and in desktop Excel for Mac. The VBA editor and some operating-system integrations differ between Windows and Mac, but the basic close instruction does not. On Windows, the VBA editor can be opened with Alt+F11; on many Mac keyboards, the equivalent is Option+F11, though the required function-key setting can vary by keyboard. Excel for the web does not run VBA macros, so use desktop Excel to execute this code.

To run a macro in desktop Excel for Windows, first save the file in a macro-enabled format such as .xlsm if the code needs to be retained, then use Developer > Macros to choose and run it. If the Developer tab is not visible, it can be enabled in Excel Options. Macro security settings may prevent execution until the workbook is trusted or macros are enabled according to your organization’s policy. Do not enable macros in an untrusted file just to close a workbook.

Alternatives when you want a different outcome

If you want to keep the edits, use SaveChanges:=True rather than False, or save the workbook explicitly before closing it. If you want Excel to ask the user, omit the argument and allow the normal save prompt to appear. That is often appropriate for an interactive workbook, while an automated process should make its save-or-discard choice explicit.

If the goal is to discard changes to a single worksheet but keep other workbook changes, closing the whole workbook without saving is too broad. You would need to manage the relevant cell or sheet changes deliberately, or work on a separate copy. Likewise, if you want to preserve a clean original while experimenting, open a duplicate or save a copy before the macro changes anything. Closing without saving is a workbook-level decision, not a selective rollback tool.

Frequently Asked Questions

What is the VBA command to close a workbook without saving?

Use wb.Close SaveChanges:=False, where wb is a variable referring to the workbook you intend to close. The named argument makes the discard choice explicit.

How do I close the active workbook without saving?

You can use ActiveWorkbook.Close SaveChanges:=False, but this targets whichever workbook is active at that moment. For more reliable automation, capture the intended workbook in a Workbook variable and close that variable.

Does SaveChanges:=False close every open workbook?

No. It applies only to the workbook object on which you call Close. Other open workbooks remain open, and Excel may still ask about unsaved changes in those separate files when they are closed.

Can I undo closing a workbook without saving?

No. Unsaved edits discarded by closing are not restored by Ctrl+Z. Recovering a previous saved version may be possible through a backup or version history, but it is not guaranteed, so make a copy before running a discard macro.

Can Excel for the web run this VBA code?

No. Excel for the web does not execute VBA macros. Open the workbook in desktop Excel for Windows or Mac to run the VBA close command.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.