XL: Prompt to Save Changed Workbook Fails to Appear (213513)



The information in this article applies to:

  • Microsoft Excel 2000
  • Microsoft Excel 2002

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 problem may occur if both of the following conditions are true:

  • You run a macro that changes the caption of the workbook window.

    -and-

  • You try to close the workbook without first saving the changes.

RESOLUTION

To resolve this problem, do either of the following:

  • Click Save on the File menu before you click Close on the File menu or click the Close button (the box with the "X" in it) at the upper-right corner of the workbook window.

    -or-

  • Add a line of Microsoft Visual Basic for Applications code in the macro to set the Saved property to False 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 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 (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.

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 retain changes 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.

REFERENCES

For more information about saving files, click Microsoft Excel Help on the Help menu, type Save a workbook in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbdtacode kbpending kbprb kbProgramming KB213513