XL: Visual Basic Macro to Save All Open Workbooks in MS ExcelLast reviewed: February 3, 1998Article ID: Q131333 |
The information in this article applies to:
SUMMARYThe following is an example of a Microsoft Visual Basic for Applications macro that automatically saves all files that have been previously saved. If files are open that have not been previously saved, a dialog box will prompt the user for a file name.
MORE INFORMATIONMicrosoft 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.aspIn Microsoft Excel, you can use the AUTOSAVE.XLA add-in macro to save all open documents automatically as you work. If you prefer not to have your documents automatically saved, but would like to save all open documents at one time, use the following sample Visual Basic for Applications macro:
Sub SaveAll() ' Store the Activeworkbook in a variable. Set aw = ActiveWorkbook For Each wb In Workbooks If wb.Path <> "" Then ' Save file if it has been saved ' previously wb.Save Else ' If not previously saved, activate and show the ' Save As dialog box. wb.Activate Application.Dialogs(xlDialogSaveAs).Show End If Next aw.Activate ' Activate the original Activeworkbook. End SubAfter you create the macro, do the following to create a menu item and assign the macro to it:
Microsoft Excel 5.0 or 7.0
Microsoft Excel 97 or Microsoft Excel 98
REFERENCES"Visual Basic User's Guide," version 5.0, Chapter 12, "Creating Menuing Items" For more information about using the Menu Editor, click the Search button in Microsoft Excel Help and type:
Menu EditorFor additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q76442 TITLE : Macro to Save All Open Worksheets in Excel |
Additional query words: 5.00 5.00a 5.00c 7.00 7.00a 97 98 XL5 XL7 XL97 XL98
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |