Microsoft KB Archive/153893

= Macro to Automatically Save Personal.xls Without Prompt =

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
 On the Window menu, click Unhide. In the "unhide workbook" list, click Personal.xls, and click OK. On the Tools menu, point to Macro, and click Visual Basic Editor.

The Visual Basic Editor appears. 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.  In the Code pane, type the following code: Sub Auto_Close ThisWorkbook.Save End Sub  On the File menu, click "Close and Return to Microsoft Excel." On the Window menu, click Hide.</li> On the File menu, click Exit to quit Microsoft Excel.</li></ol>

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
<ol> On the Window menu, click Unhide.

If you have a Personal.xls file, it is listed in the Unhide dialog box.</li> Click Personal.xls and click Unhide.</li> On the Insert menu, click Macro, and then click Module.</li>  Type the following macro code into the module sheet: Sub Auto_Close ThisWorkbook.Save 'Saves the workbook the macro is in. End Sub </li> On the File menu, click Save.</li> On the Window menu, click Hide.</li> On the File menu, click Exit.</li></ol>

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
<ol> On the Window menu, click Unhide.

If you have a Personal Macro Workbook, it is listed in the Unhide dialog box.</li> Click Personal Macro Workbook and then click Unhide.</li> On the Insert menu, click Macro, and then click Module.</li>  Type the following macro code into the module sheet: Sub Auto_Close ThisWorkbook.Save 'Saves the workbook the macro is in. End Sub </li> On the File menu click Save.</li> On the Window menu, click Hide.</li> On the File menu, click Quit.</li></ol>

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.

<div class="references_section">