You are currently offline, waiting for your internet to reconnect

How to suppress "Save Changes" prompt when you close a workbook in Excel

Support for Office 2003 has ended

Microsoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

This article was previously published under Q213428
For a Microsoft Excel 97 and earlier version of this article, see 129153.
In Microsoft Excel, you can create a Microsoft Visual Basic forApplications (VBA) macro that suppresses the "Save Changes" prompt when youclose a workbook. You can do this either by specifying the state of theworkbook's Saved property or by suppressing all alerts for the workbook.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

To use either of the following examples, follow these steps:
  1. Start Excel and open a new workbook.
  2. Press ALT+F11 to start the Visual Basic editor.
  3. On the Insert menu, click Module.
  4. Type the sample macro code into the module sheet.
  5. Press ALT+F11 to return to Excel.
  6. In Microsoft Office Excel 2003 and in earlier versions of Excel, point to Macro on the Tools menu, and then click Macros.

    In Microsoft Office Excel 2007, click Macros in the Code group on the Developer tab.

    Note If the Developer tab is not available, consider the following steps:
    1. Click the Microsoft Office Button, and then click Excel Options.
    2. In the Popular category, under Top options for working with Excel, click to select the Show Developer tab in the Ribbon check box, and then click OK.
  7. Select the macro that you want, and then click Run.
The Saved property returns the value False if changes have been made to a workbook since it was last saved.

You can use the reserved subroutine name "Auto_Close" to specify a macrothat should run whenever a workbook is closed. By doing this, you cancontrol how the document is handled when the user is finished and hasinstructed Excel to close the document.

Example 1: Close the workbook without saving changes

To force a workbook to close without saving any changes, type the followingcode in a Visual Basic module of that workbook:
Sub Auto_Close()    ThisWorkbook.Saved = TrueEnd Sub				
Because the Saved property is set to True, Excel responds as though the workbook has already been saved and no changes have occurred since that last save.

The DisplayAlerts property of the program can be used for the same purpose. For example, the following macro turns DisplayAlerts off, closes the active workbook without saving changes, and then turns DisplayAlerts on again.
Sub CloseBook()    Application.DisplayAlerts = False    ActiveWorkbook.Close    Application.DisplayAlerts = TrueEnd Sub				
You can also use the SaveChanges argument of the Close method.

The following macro closes the workbook without saving changes:
Sub CloseBook2()    ActiveWorkbook.Close savechanges:=FalseEnd Sub				

Example 2: Close the workbook and save the changes

To force a workbook to save changes, type the following code in a Visual Basic module of that workbook:
Sub Auto_Close()    If ThisWorkbook.Saved = False Then        ThisWorkbook.Save    End IfEnd Sub				
This subprocedure checks to see if the file's Saved property is set to False. If so, the workbook has been changed since the last save, and those changes are saved.
XL2000 xl2002 XL2003 xl2007 kbnoOfficeAlertID

Article ID: 213428 - Last Review: 05/28/2007 03:50:07 - Revision: 5.1

  • Microsoft Office Excel 2007
  • Microsoft Office Excel 2003
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Excel 2000 Standard Edition
  • kbdtacode kbhowto kbprogramming KB213428