Microsoft KB Archive/153893

From BetaArchive Wiki

Article ID: 153893

Article Last Modified on 10/11/2006



APPLIES TO

  • Microsoft Excel 97 Standard Edition
  • Microsoft Excel 95 Standard Edition
  • Microsoft Excel 5.0 Standard Edition



This article was previously published under Q153893

SUMMARY

When you edit the Personal.xls file in Microsoft Excel for Windows (or the Personal Macro Workbook in Microsoft Excel for the Macintosh), you are asked to save changes to it when you quit Microsoft Excel.

This article describes how to create a macro that prevents the message from appearing and that saves the changes automatically when you close the file.

For information about the purpose and location of this file, see the "Background" section later in this article.

MORE INFORMATION

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. To automatically save the macro file when you quit Microsoft Excel, use the appropriate method for your situation.

Microsoft Excel 97 for Windows

  1. On the Window menu, click Unhide.
  2. In the "unhide workbook" list, click Personal.xls, and click OK.
  3. On the Tools menu, point to Macro, and click Visual Basic Editor.

    The Visual Basic Editor appears.
  4. In the Project pane, click the plus sign next to "VBAProject (PERSONAL.XLS)". Then, click the plus sign next to "Modules." Double-click one of the modules listed as part of PERSONAL.XLS.
  5. In the Code pane, type the following code:

          Sub Auto_Close()
             ThisWorkbook.Save
          End Sub
                            
  6. On the File menu, click "Close and Return to Microsoft Excel."
  7. On the Window menu, click Hide.
  8. On the File menu, click Exit to quit Microsoft Excel.

You should not be prompted to save the Personal.xls file when you quit Microsoft Excel.

Microsoft Excel 5.0 and 7.0 for Windows

  1. On the Window menu, click Unhide.

    If you have a Personal.xls file, it is listed in the Unhide dialog box.
  2. Click Personal.xls and click Unhide.
  3. On the Insert menu, click Macro, and then click Module.
  4. Type the following macro code into the module sheet:

          Sub Auto_Close()
             ThisWorkbook.Save  'Saves the workbook the macro is in.
          End Sub
                            
  5. On the File menu, click Save.
  6. On the Window menu, click Hide.
  7. On the File menu, click Exit.

When you quit Microsoft Excel, you are not prompted to save changes to the Personal.xls file. Instead, the changes are saved automatically.

Microsoft Excel 5.0 for the Macintosh

  1. On the Window menu, click Unhide.

    If you have a Personal Macro Workbook, it is listed in the Unhide dialog box.
  2. Click Personal Macro Workbook and then click Unhide.
  3. On the Insert menu, click Macro, and then click Module.
  4. Type the following macro code into the module sheet:

          Sub Auto_Close()
             ThisWorkbook.Save  'Saves the workbook the macro is in.
          End Sub
                            
  5. On the File menu click Save.
  6. On the Window menu, click Hide.
  7. On the File menu, click Quit.

When you quit Microsoft Excel, you are not prompted to save changes to the Personal Macro Workbook file. Instead, the changes are saved automatically.

Background

Excel stores custom macros in the Personal.xls file in Microsoft Excel for Windows and the Personal Macro Workbook in Microsoft Excel for the Macintosh.

In Microsoft Excel for Windows, the Personal.xls file normally resides in the \Excel\Xlstart folder. In Microsoft Excel for the Macintosh, the Personal Macro Workbook normally resides in the "System Folder:Preferences: Excel Startup Folder(5)" folder.

When you open Microsoft Excel, the Personal macro Workbook opens automatically but is hidden. If you record a new macro and specify that the macro be recorded into the Personal.xls or Personal Macro Workbook, or if you edit it in any way, you will be prompted to save it when you quit Microsoft Excel. Simply unhiding workbook and then rehiding it counts as a change, and you will be prompted to save changes when you quit Microsoft Excel.

REFERENCES

For more information about the Close event in Microsoft Excel 97, click the Office Assistant, type close event, click Search, and then click to view "WorkbookBeforeClose Event."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:

176476 OFF: Office Assistant Not Answering Visual Basic Questions


"Microsoft Excel Visual Basic Programmer's Guide," pages 205-210

"Visual Basic User's Guide," version 5.0, Chapter 13, Creating Automatic Procedures and Add-in Applications

For more information about Auto_Close macros, click the Index tab in Microsoft Excel Help, and type the following text:

auto_close



Additional query words: 5.00a 5.00c 7.00a 97 8.00 xl97 XL

Keywords: kbdtacode kbhowto kbprogramming KB153893