Saving and Closing multiple files and Excel program

  • Thread starter Thread starter Roger
  • Start date Start date
R

Roger

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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top