ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close all inactive workbooks without saving (https://www.excelbanter.com/excel-programming/417984-close-all-inactive-workbooks-without-saving.html)

Basta1980

Close all inactive workbooks without saving
 
Hi,

Anyone knows how close all inactive workbooks without saving and thus having
just one workbeek (the active)?!

Thnx

papou[_4_]

Close all inactive workbooks without saving
 
Hello

Dim wWorkb As Workbook
For Each wWorkb In Application.Workbooks
If wWorkb.Name < ActiveWorkbook.Name Then wWorkb.Close (False)
Next wWorkb

HTH
Cordially
Pascal

"Basta1980" a écrit dans le message de
news: ...
Hi,

Anyone knows how close all inactive workbooks without saving and thus
having
just one workbeek (the active)?!

Thnx




jgmiddel[_9_]

Close all inactive workbooks without saving
 
This should work:

Sub CloseAll()
Dim WkbkName As Object
On Error GoTo Close_Error
For Each WkbkName In Application.Workbooks()
If WkbkName.Name < ThisWorkbook.Name Then WkbkName.Close
savechanges:=False
Next
Close_Error:
Resume Next
End Sub


All times are GMT +1. The time now is 09:22 PM.

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