Microsoft KB Archive/213513

= You are not prompted to save the changes when you change and close a workbook in Excel =

Article ID: 213513

Article Last Modified on 1/2/2007

-

APPLIES TO


 * Microsoft Office Excel 2007
 * Microsoft Office Excel 2003
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213513





For a Microsoft Excel 97 version of this article, see 173113.



For a Microsoft Excel 98 version of this article, see 183610.



SYMPTOMS
When you change and then close a workbook in Microsoft Excel, you are not prompted to save the changes.



CAUSE
This issue may occur if the following conditions are true:
 * You run a macro that changes the caption of the workbook window.
 * You try to close the workbook without first saving the changes.



RESOLUTION
To resolve this issue, do either of the following:
 * Press CTRL+S to save the changes before you close the workbook.
 * Add a line of Microsoft Visual Basic for Applications (VBA) code in the macro to set the Saved property to False. Do this after the line that sets the Caption property of the workbook window.

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, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The sample macro prompts you to save the workbook. To use the macro, follow these steps:  Start Excel and create a new workbook. Press ALT+F11 to open the Visual Basic Editor. On the Insert menu, click Module.  Type the following code into the new module. Sub Caption_Macro

'           'More code here. '

'Changes the Caption property of the first window Windows(1).Caption = "Window 1"

'Setting that the workbook has changed. ActiveWorkbook.Saved = False

'           'More code here. '

End Sub  Switch to Excel. To do this, press ALT+F11.</li> On the Tools menu, point to Macro, and click Macros. Click Caption_macro and click Run.</li> On the File menu, click Close.</li></ol>

You receive a message that prompts you to save the workbook.

<div class="moreinformation_section">

MORE INFORMATION
In most cases, if you attempt to close a changed workbook that you have not saved, you are prompted to save the changes. To save changes that you want to keep, save them before you close the workbook.

The Saved property returns a True or False value depending on whether changes have been made to the workbook. Note that it is possible to set the Saved property to True or False.

Additional query words: XL2000 XL2003 XL2007

Keywords: kbexpertisebeginner kbdtacode kbpending kbprb kbprogramming KB213513

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.