XL: Macro to Automatically Save Personal.xls Without Prompt

Last reviewed: December 1, 1997
Article ID: Q153893
The information in this article applies to:
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a

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 exit Microsoft Excel.

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

For information on the purpose and location of this file, see the "Background" section at the end of this article.

MORE INFORMATION

Microsoft 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.asp

Use one of the following methods to automatically save the macro file when you quit Microsoft Excel:

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

The Personal.xls file in Microsoft Excel for Windows and the Personal Macro Workbook in Microsoft Excel for the Macintosh are used to store custom macros.

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

"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.00 5.00a 5.00c 7.00 7.00a 97 8.00 xl97
Keywords : kbcode kbprg PgmHowto
Version : WINDOWS:5.0,5.0c.7.0,7.0a,97; MACINTOSH:5.0
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.