save all workbooks

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
385
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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

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
 

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,872
Messages
5,766,864
Members
425,382
Latest member
IronM

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