Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


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

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

↑ Back to the top


Symptoms

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

↑ Back to the top


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.

↑ Back to the top


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:
  1. Start Excel and create a new workbook.
  2. Press ALT+F11 to open the Visual Basic Editor.
  3. On the Insert menu, click Module.
  4. 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
  5. Switch to Excel. To do this, press ALT+F11.
  6. On the Tools menu, point to Macro, and click Macros. Click
    Caption_macro and click Run.
  7. On the File menu, click Close.
You receive a message that prompts you to save the workbook.

↑ Back to the top


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.

↑ Back to the top


Keywords: kboffice12yes, kbfreshness2006, kbexpertisebeginner, kbbillprodsweep, 2000rtmpublic, kbdtacode, kbpending, kbprb, kbprogramming, offcon, kb, epucon

↑ Back to the top

Article Info
Article ID : 213513
Revision : 9
Created on : 8/20/2020
Published on : 8/21/2020
Exists online : False
Views : 124