ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Saving and Closing multiple files and Excel program (https://www.excelbanter.com/excel-programming/334437-saving-closing-multiple-files-excel-program.html)

Roger[_20_]

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



BrianB

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


Roger B.

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




BrianB

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


Roger B.

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





All times are GMT +1. The time now is 08:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com