Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Saving and Closing multiple files and Excel program
I am looking for 2 macros that I had in Excel 5 which don't work in Excel
2002. The first is a macro that Saves and Closes all open files except any file which is BOOK1, or BOOK2 etc. The second is a macro that Closes all open files and doesn't save them except any file which is BOOK1, or BOOK2 etc. In both cases the workbook is left open and the BOOK files are not saved. Any help would be greatly appreciated, Roger |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Saving and Closing multiple files and Excel program
Like tihs ? Code: -------------------- Sub SaveBooksUntested() Dim MySave As Boolean rsp = MsgBox("Save Non 'Book' files ?", vbYesNoCancel) If rsp = vbCancel Then Exit Sub If rsp = vbYes Then MySave = True If rsp = vbYes Then MySave = False '----------------------------------------------------------- For Each wb In Workbooks If wb.Name < "Book1.xls" And wb.Name < "Book2.xls" Then wb.Close savechanges:=MySave End If Next End Sub -------------------- -- BrianB ------------------------------------------------------------------------ BrianB's Profile: http://www.excelforum.com/member.php...info&userid=55 View this thread: http://www.excelforum.com/showthread...hreadid=386951 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Saving and Closing multiple files and Excel program
Hi Brian, many thanks for your code. I wrestled with it for a couple of
hours to get it to work but no luck. Here is the macro that I was working on. Your macro seemed to work for the Book1 etc files but not for the other files. I want to keep only these files open if they are already open. Can you see where I went wrong? Many thanks, Roger Sub KeepingSpecialFilesOpen() Dim book As Variant For Each book In Workbooks If book.Name < "Book1" Or book.Name < "Book2" Or book.Name < "Book3" Or book.Name < "Book4" Or book.Name < "Book5" Or book.Name < "Work04.xls" Or book.Name < "WORK05.XLS" Then book.Close saveChanges:=True Next book End Sub "BrianB" wrote in message ... Like tihs ? Code: -------------------- Sub SaveBooksUntested() Dim MySave As Boolean rsp = MsgBox("Save Non 'Book' files ?", vbYesNoCancel) If rsp = vbCancel Then Exit Sub If rsp = vbYes Then MySave = True If rsp = vbYes Then MySave = False '----------------------------------------------------------- For Each wb In Workbooks If wb.Name < "Book1.xls" And wb.Name < "Book2.xls" Then wb.Close savechanges:=MySave End If Next End Sub -------------------- -- BrianB ------------------------------------------------------------------------ BrianB's Profile: http://www.excelforum.com/member.php...info&userid=55 View this thread: http://www.excelforum.com/showthread...hreadid=386951 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Saving and Closing multiple files and Excel program
If you compare the 2 sets of code carefully your common error is obvious. ;) -- BrianB ------------------------------------------------------------------------ BrianB's Profile: http://www.excelforum.com/member.php...info&userid=55 View this thread: http://www.excelforum.com/showthread...hreadid=386951 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Saving and Closing multiple files and Excel program
Brian, I see several items that are different. I tried most variations but
didn't get anywhere. Why does it want to save the Book1 etc files? Tks, Roger "BrianB" wrote in message ... If you compare the 2 sets of code carefully your common error is obvious. ;) -- BrianB ------------------------------------------------------------------------ BrianB's Profile: http://www.excelforum.com/member.php...info&userid=55 View this thread: http://www.excelforum.com/showthread...hreadid=386951 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
excel creates multiple temp files when saving | Excel Discussion (Misc queries) | |||
Excel program remains open after closing file | Excel Discussion (Misc queries) | |||
How can I exit a workbook in Excel without closing the program? | Excel Discussion (Misc queries) | |||
Closing files and saving files | Excel Worksheet Functions | |||
Importing/saving multiple files in Excel w/ macro | Excel Programming |