save all workbooks

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
389
Hi,

Is there a piece of code that will save all workbooks that are open?

So if I have 5 spreadsheets that is open, can all of them be saved one after the other.

Cheers

Jay
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

MartinK

Active Member
Joined
Oct 30, 2003
Messages
384
Try:
Code:
Sub CloseAll()
Dim wbk As Workbook
For Each wbk In Workbooks
    Application.DisplayAlerts = False
           wbk.Close SaveChanges:=False
    Application.DisplayAlerts = True
Next wbk
End Sub

Or simply:
Code:
Workbooks.Close
(displays dialogs)
Martin
 
Upvote 0

Iridium

Well-known Member
Joined
Jul 15, 2002
Messages
2,831
From MS KB: XL2000: How to Programmatically Save All Open Workbooks

Code:
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 Sub

HTH
 
Upvote 0

Forum statistics

Threads
1,186,363
Messages
5,957,418
Members
438,304
Latest member
duck90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top