ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save and Close (https://www.excelbanter.com/excel-programming/454115-save-close.html)

Paul Doucette

Save and Close
 
Is there code I can put into a my personal workbook which would allow me to save and close all of open workbooks? I have several that are quite large and often end up with a dozen open at the end of the day, so it would be a time saver.
Thanks!

Paul Doucette

Save and Close
 
On Wednesday, June 20, 2018 at 4:12:53 PM UTC-4, Paul Doucette wrote:
Is there code I can put into a my personal workbook which would allow me to save and close all of open workbooks? I have several that are quite large and often end up with a dozen open at the end of the day, so it would be a time saver.
Thanks!


Thanks Claus!

Sub CloseAndSave()
Dim wbk As Workbook

Application.ScreenUpdating = False
For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
wbk.Close True
End If
Next
Application.ScreenUpdating = True
Application.Quit
End Sub

Ilia Asafiev

Save and Close
 
On Thursday, June 21, 2018 at 10:49:17 AM UTC-4, Paul Doucette wrote:
On Wednesday, June 20, 2018 at 4:12:53 PM UTC-4, Paul Doucette wrote:
Is there code I can put into a my personal workbook which would allow me to save and close all of open workbooks? I have several that are quite large and often end up with a dozen open at the end of the day, so it would be a time saver.
Thanks!


Thanks Claus!

Sub CloseAndSave()
Dim wbk As Workbook

Application.ScreenUpdating = False
For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
wbk.Close True
End If
Next
Application.ScreenUpdating = True
Application.Quit
End Sub


I would add a check to see whether it is Read-only or not, otherwise you could get a runtime error.

Paul Doucette

Save and Close
 
On Thursday, June 21, 2018 at 12:37:04 PM UTC-4, Ilia Asafiev wrote:
On Thursday, June 21, 2018 at 10:49:17 AM UTC-4, Paul Doucette wrote:
On Wednesday, June 20, 2018 at 4:12:53 PM UTC-4, Paul Doucette wrote:
Is there code I can put into a my personal workbook which would allow me to save and close all of open workbooks? I have several that are quite large and often end up with a dozen open at the end of the day, so it would be a time saver.
Thanks!


Thanks Claus!

Sub CloseAndSave()
Dim wbk As Workbook

Application.ScreenUpdating = False
For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
wbk.Close True
End If
Next
Application.ScreenUpdating = True
Application.Quit
End Sub


I would add a check to see whether it is Read-only or not, otherwise you could get a runtime error.


Thanks!


All times are GMT +1. The time now is 02:49 PM.

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