Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Close all other workbooks but this one?

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

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Close all other workbooks but this one?

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

"ianripping " skrev i melding
...
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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
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/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Close all other workbooks but this one?

Thanks, works great

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
Open Close workbooks bbc1 Excel Discussion (Misc queries) 2 August 28th 05 11:24 AM
Why does Excel close all workbooks? JVernon Setting up and Configuration of Excel 1 July 5th 05 10:38 PM
So close yet so far - combining workbooks happy Excel Programming 17 May 20th 04 04:05 AM
help with macro to open and close workbooks aneurin Excel Programming 1 September 24th 03 02:14 AM


All times are GMT +1. The time now is 11:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"