ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to save & close all opened files (https://www.excelbanter.com/excel-discussion-misc-queries/123616-macro-save-close-all-opened-files.html)

James A

Macro to save & close all opened files
 
Is there any way to record a macro to save and close alll open files?
--
James A

Tim Lindsley

Macro to save & close all opened files
 
Hi James,

I don't know about closing all files, but to close save and close all
Excel workbooks, put this macro in a common module or ThisWorkbook
module. This will save the workbook with the code last and then close
the entire excel application.

Sub CloseWorkbooks()

Dim wkbk As Workbook

'loop through workbook collection
For Each wkbk In Application.Workbooks
If wkbk.Name < ThisWorkbook.Name Then
wkbk.Close True
Else
End If
Next wkbk

'save this workbook
ThisWorkbook.Save
'close the excel application
Application.Quit
End Sub

Regards,

Tim

James A wrote:
Is there any way to record a macro to save and close alll open files?
--
James A




All times are GMT +1. The time now is 04:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com