View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Nikos Yannacopoulos[_5_] Nikos Yannacopoulos[_5_] is offline
external usenet poster
 
Posts: 80
Default Close all other workbooks but this one?

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

"ianripping " wrote in message
...
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 and
close them all apart from this open one?


---
Message posted from http://www.ExcelForum.com/