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 open workbooks except the active one


I am sure the answer is very simple, but at the start of a macro, I wish
to close all the workbooks that are not the activeworkbook (which
contains the macro). Can anyone tell me how.

Thanks in advance

Dav


--
Dav
------------------------------------------------------------------------
Dav's Profile: http://www.excelforum.com/member.php...o&userid=27107
View this thread: http://www.excelforum.com/showthread...hreadid=529987

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default close all open workbooks except the active one

Hi Dav,

This worked on my PC:

Sub closeAllOtherWb()
Dim wkbWorkbook As Workbook

For Each wkbWorkbook In Workbooks
If wkbWorkbook.Name < ThisWorkbook.Name Then wkbWorkbook.Close
Next wkbWorkbook
End Sub
--
Stefano Gatto


"Dav" wrote:


I am sure the answer is very simple, but at the start of a macro, I wish
to close all the workbooks that are not the activeworkbook (which
contains the macro). Can anyone tell me how.

Thanks in advance

Dav


--
Dav
------------------------------------------------------------------------
Dav's Profile: http://www.excelforum.com/member.php...o&userid=27107
View this thread: http://www.excelforum.com/showthread...hreadid=529987


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default close all open workbooks except the active one


Thanks for your help

That works excellently. I knew there would be a simple way, but it was
beyond me in finding it. The answer is always simple when you know
how!

Cheers

Dav


--
Dav
------------------------------------------------------------------------
Dav's Profile: http://www.excelforum.com/member.php...o&userid=27107
View this thread: http://www.excelforum.com/showthread...hreadid=529987

  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default close all open workbooks except the active one

Just pointing out that if changes were made to any of the open workbooks
since the last save, Excel will prompt users to save changes (which comes
with a cancel button). It is possible not all workbooks will be closed.
You'll need to decide whether or not this is problem depending on who is
running the macro and what problems it could cause.


"Dav" wrote:


Thanks for your help

That works excellently. I knew there would be a simple way, but it was
beyond me in finding it. The answer is always simple when you know
how!

Cheers

Dav


--
Dav
------------------------------------------------------------------------
Dav's Profile: http://www.excelforum.com/member.php...o&userid=27107
View this thread: http://www.excelforum.com/showthread...hreadid=529987


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
How to close all open workbooks in Excel 2007 Alojz Setting up and Configuration of Excel 0 September 17th 09 11:04 PM
Workbooks Close, but window stays open Mari Excel Discussion (Misc queries) 2 January 16th 08 09:00 PM
How to close specific workbook not all active workbooks? Bon Excel Programming 1 January 20th 06 02:49 PM
Open Close workbooks bbc1 Excel Discussion (Misc queries) 2 August 28th 05 11:24 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 02:31 PM.

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"