![]() |
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 |
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 |
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 |
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 |
CLOSE WB
Does my code do what you asked?
Die_Another_Day |
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 |
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 |
CLOSE WB
Oops. Add .xls on the end of Workbook 2 and make sure that it's spelled
correctly Die_Another_Day |
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 |
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 |
All times are GMT +1. The time now is 04:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com