Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Close all other open Workbooks

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Close all other open Workbooks

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
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"CLR" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Close all other open Workbooks

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

--
Gary''s Student - gsnu200817
  #4   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Close all other open Workbooks

Thanks Barb.......
Appreciate the quick comeback.........

Vaya con Dios,
Chuck, CABGx3

"Barb Reinhardt" wrote:

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
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"CLR" wrote:

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Close all other open Workbooks

Thanks Gary"s Student....
Appreciate the quick comeback

Vaya con Dios,
Chuck, CABGx3



"Gary''s Student" wrote:

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

--
Gary''s Student - gsnu200817

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
Code to close many open workbooks MurrayB Excel Programming 13 September 18th 08 01:32 PM
Workbooks Close, but window stays open Mari Excel Discussion (Misc queries) 2 January 16th 08 09:00 PM
close all open workbooks except the active one Dav[_4_] Excel Programming 3 April 6th 06 01:26 AM
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 10:55 AM.

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

About Us

"It's about Microsoft Excel"