Excel, Don't Save

techmanbd

Well-known member
Joined
Sep 10, 2003
Messages
398
Location
Burbank, CA
In my code I open an excel sheet, already made up, that inserts info into certain cells then I print it out. No when I close the excel workgroup I get the message ----- If I Want To Save My Changes. generated from the excel program when closing

I remember way back in the day with VB5 that I was able to set something so that it would basically not ask that. I dont want to save what I inserted.

Anybody know the command?
Thanks
 
The xlApp.Quit routine calls xlApp.Workbooks.Close behind the scenes. If any are unsaved, then you get the alert displayed. But, yes, it can be turned off.

In the following, Ill assume that your Excel.Application reference is called xlApp and that your Excel.Workbook reference is called xlWB. You kind of have four choices here. Either:

(1) The easiest is simply to turn DisplayAlerts off:
Code:
 xlApp.DisplayAlerts = False
xlApp.Quit
xlApp = Nothing

(2) Close your Workbook without saving changes:
Code:
xlWB.Close(False)   SaveChanges:= False
xlApp.Quit
xlApp = Nothing

(3) "Trick" XL into thinking that your WB is already saved, without saving it at all!
Code:
 xlWB.Saved = True
xlApp.Quit    No alert will happen here, XL thinks xlWB is saved.
xlApp = Nothing

(4) Save your workbook... which you said you didnt want, but for completeness:
Code:
 xlWB.SaveAs("C:\My Documents\Book1.xls")
xlApp.Quit
xlApp = Nothing
Hope this helps...

:),
Mike
 
Back
Top