Close all other workbooks but this one?

I

ianripping

If I have 3 workbooks open and I only want to have open (this) workbook
is there a way to make excel find the number of open worksheets an
close them all apart from this open one
 
H

Harald Staff

Sub test()
Dim WB As Workbook
For Each WB In Application.Workbooks
If WB.FullName <> Me.FullName Then WB.Close
Next
End Sub

As is it will ask "save changes ?" for each one.

HTH. Best wishes Harald
 
N

Nikos Yannacopoulos

Sub close_all_other_workbooks()
ThisWkbk = ActiveWorkbook.Name
For i = Workbooks.Count To 1 Step -1
If Workbooks(i).Name <> ThisWkbk And Workbooks(i).Name <> "Personal.xls"
Then
Workbooks(i).Close 'False
End If
Next
End Sub

Uncommenting the False switch will close without saving, using True instead
will save and close; as is, you will be prompted.

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top