Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA-How to close all open workbooks except one specific?

I have a macro that will close all open workbooks, works great. Now I
would like to have this macro close all open workbooks except one
specific files, KeyWest.xls. The below code works and I imagine a
simple IF Then sort of statement might solve my problem but I cannot
figure it out. Thanks for any help!

Ryan

Public Sub CloseAll()

Dim WB As Workbook

SaveAll
For Each WB In Workbooks
If Not WB.Name = ThisWorkbook.Name Then
WB.Close SaveChanges:=True
End If
Next WB

ThisWorkbook.Close SaveChanges:=True
End Sub


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel VBA-How to close all open workbooks except one specific?

Hi Ryan,

It currently closes all workbooks except Thisworkbook (the workbook
containing this code). Do you just want to change from This workbook to Key
west.xls? If so, be aware that if Thisworkbook is not Key West, you will
close ThisWorkbook, at which point the macro cannot run any longer.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"waveracerr " wrote in message
...
I have a macro that will close all open workbooks, works great. Now I
would like to have this macro close all open workbooks except one
specific files, KeyWest.xls. The below code works and I imagine a
simple IF Then sort of statement might solve my problem but I cannot
figure it out. Thanks for any help!

Ryan

Public Sub CloseAll()

Dim WB As Workbook

SaveAll
For Each WB In Workbooks
If Not WB.Name = ThisWorkbook.Name Then
WB.Close SaveChanges:=True
End If
Next WB

ThisWorkbook.Close SaveChanges:=True
End Sub


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Excel VBA-How to close all open workbooks except one specific?

If You've placed this macro in KeyWest.xls, what suggests the line:
If Not WB.Name = ThisWorkbook.Name Then

then remove the line:
ThisWorkbook.Close SaveChanges:=True

otherwise change the first mentioned line to:
If Not WB.Name = "KeyWest.xls" Then

Tomek


"waveracerr " wrote in message
...
I have a macro that will close all open workbooks, works great. Now I
would like to have this macro close all open workbooks except one
specific files, KeyWest.xls. The below code works and I imagine a
simple IF Then sort of statement might solve my problem but I cannot
figure it out. Thanks for any help!

Ryan

Public Sub CloseAll()

Dim WB As Workbook

SaveAll
For Each WB In Workbooks
If Not WB.Name = ThisWorkbook.Name Then
WB.Close SaveChanges:=True
End If
Next WB

ThisWorkbook.Close SaveChanges:=True
End Sub


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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA-How to close all open workbooks except one specific?

Ah great, I somehow missed the code:

ThisWorkbook.Close SaveChanges:=True


Teach me not to just copy and paste....

Thanks


---
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
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
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
Can I have a loop to open a set of workbooks get some data, close it one a time. wellie Excel Programming 2 July 9th 03 04:58 AM


All times are GMT +1. The time now is 02:36 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"