#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default CLOSE WB

I am looking for code that will close all open workbooks except for the
active one and "Workbook 2" w/o saving changes.

Any help is very much appreciated.

Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default CLOSE WB

Ronbo,

Are you trying to write a macro virus???

That kind action from your code would be potentially harmful to
people's data and make you a very unpopular bunny.

NickH

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default CLOSE WB

Sub KillWBs() 'I'm crazy and want to loose all my changes
Dim WB as Workbook
Dim File1 as Workbook
Set File1 = ActiveWorkbook
For each WB in Application.Workbooks
if WB.Name = "Workbook 2" or WB.Name = File1.Name then
'Don't Close
Else
WB.Close False
End If
Next

Die_Another_Day

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default CLOSE WB

No virus, just a macro that will clean-up numerous open workbooks that have
been used in creating a master wb and are no longer needed and do not need to
be saved. This saves the time of going into each and shutting them down.
And it is only used on my computer.

I saw code on "close all but active", but I need the active and "workbook
2" to remain open.

"NickH" wrote:

Ronbo,

Are you trying to write a macro virus???

That kind action from your code would be potentially harmful to
people's data and make you a very unpopular bunny.

NickH


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default CLOSE WB

Does my code do what you asked?

Die_Another_Day



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default CLOSE WB

If you are copying a worksheet to a new workbook, try moving it instead. I
have a macro that grabs several worksheets from various sources and moves
them to a new workbook. When the worksheet is moved, it automatically closes
the original workbook. (It's the only worksheet in the original)

ChDir "\\ma-sql\erp7\FRx\IODATA\OPxRAW"
Workbooks.Open Filename:="\\ma-sql\erp7\FRx\IODATA\OPxRAW\COO.xls"
Sheets("COO").Select
Sheets("COO").Move Befo=Workbooks("FormatOPx.xls").Sheets(1)

** You would replace anything in quotes with your data **

"Ronbo" wrote in message
...
No virus, just a macro that will clean-up numerous open workbooks that
have
been used in creating a master wb and are no longer needed and do not need
to
be saved. This saves the time of going into each and shutting them down.
And it is only used on my computer.

I saw code on "close all but active", but I need the active and "workbook
2" to remain open.

"NickH" wrote:

Ronbo,

Are you trying to write a macro virus???

That kind action from your code would be potentially harmful to
people's data and make you a very unpopular bunny.

NickH




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default CLOSE WB

Thaniks for the help, however as I test the code it closes all but the active
wb (File 1). Any ideas why it is closing "workbook 2"?

Ronbo

"Ronbo" wrote:

No virus, just a macro that will clean-up numerous open workbooks that have
been used in creating a master wb and are no longer needed and do not need to
be saved. This saves the time of going into each and shutting them down.
And it is only used on my computer.

I saw code on "close all but active", but I need the active and "workbook
2" to remain open.

"NickH" wrote:

Ronbo,

Are you trying to write a macro virus???

That kind action from your code would be potentially harmful to
people's data and make you a very unpopular bunny.

NickH


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default CLOSE WB

Oops. Add .xls on the end of Workbook 2 and make sure that it's spelled
correctly

Die_Another_Day

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default CLOSE WB

It still does not work with .xls and spelled correctly. Any other ideas?


"Die_Another_Day" wrote:

Oops. Add .xls on the end of Workbook 2 and make sure that it's spelled
correctly

Die_Another_Day


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default CLOSE WB

Never mind I got it. Its; If WB.Name = ("Workbook 2.xls") Or WB.Name =
File1.Name Then

Thanks a a lot for the help.

"Ronbo" wrote:

It still does not work with .xls and spelled correctly. Any other ideas?


"Die_Another_Day" wrote:

Oops. Add .xls on the end of Workbook 2 and make sure that it's spelled
correctly

Die_Another_Day


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
Not close thead when I close excel wakeup[_3_] Excel Programming 0 December 5th 05 08:57 AM
close button does not close goplayoutside Excel Discussion (Misc queries) 1 October 11th 05 03:42 PM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
excel - Windows close button (x) should only close active workboo. CoffeeAdict Setting up and Configuration of Excel 3 February 8th 05 04:30 AM


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