Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default 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
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
excel creates multiple temp files when saving westbrom Excel Discussion (Misc queries) 7 September 25th 13 04:09 PM
Excel program remains open after closing file RPC Excel Discussion (Misc queries) 9 February 7th 08 07:59 PM
How can I exit a workbook in Excel without closing the program? cosborn Excel Discussion (Misc queries) 1 September 21st 06 09:19 PM
Closing files and saving files dan Excel Worksheet Functions 0 August 15th 06 04:07 AM
Importing/saving multiple files in Excel w/ macro Mike M[_2_] Excel Programming 3 January 18th 05 02:13 PM


All times are GMT +1. The time now is 11:36 AM.

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"