XL: How to Avoid "Save Changes?" When You Close a WorkbookLast reviewed: February 3, 1998Article ID: Q129153 |
The information in this article applies to:
SUMMARYIn Microsoft Excel, you can create a Microsoft Visual Basic for Applications macro that suppresses the "Save Changes?" prompt when you close a workbook. You can do this either by specifying the state of the workbook's Saved property or by suppressing all alerts for the workbook.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/default.aspBefore working with each example below, perform the following steps:
You can use the reserved subroutine name "Auto_Close" to specify a macro that should run whenever a workbook is closed. By doing this, you can control how the document is handled when the user is finished and has instructed Microsoft Excel to close it.
Example 1: Closing the Workbook Without Saving ChangesTo force a workbook to close without saving any changes, use the following code in a Visual Basic module sheet of that workbook:
Sub Auto_Close() ThisWorkbook.Saved = True End SubBecause the Saved property is set to True, Microsoft Excel thinks the workbook has already been saved and that no changes have occurred since that last save. The DisplayAlerts property of the application 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 = True End SubYou can also do this by using the SaveChanges argument of the Close method. The following macro closes the workbook without saving changes:
Sub CloseBook2() ActiveWorkbook.Close savechanges:=False End Sub Example 2: Closing the Workbook and Saving the ChangesTo force a workbook to save changes, use the following code on a module sheet of that workbook:
Sub Auto_Close() If ThisWorkbook.Saved = False Then ThisWorkbook.Save End If End SubThis subroutine checks to see if the file's Saved property is False. If so, then the workbook has been changed since the last save, and it saves those changes. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q63815 TITLE : Excel: Avoiding "Save Changes?" When Closing a Macro Sheet |
Additional query words: 5.00 5.00a 5.00c 7.00 8.00 Mac XL5 XL7 XL97 XL98
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |