Close all other open Workbooks

  • Thread starter Thread starter CLR
  • Start date Start date
C

CLR

Hi all..........

Need code if you please to close all other open workbooks except the one I'm
running the macro in. I do not know what their names are.

TIA
Vaya con Dios,
Chuck, CABGx3
 
Try something like this

Dim WB as Workbook

For each WB in Application.Workbooks
if wb.name <> thisworkbook.name then
WB.Close 'You may want to save or do something else here
end if
next WB
 
Sub clr()
nm = ThisWorkbook.Name
Dim w As Workbook
For Each w In Workbooks
If w.Name = nm Then
Else
w.Close
End If
Next
End Sub
 
Back
Top