techmanbd Posted October 21, 2003 Posted October 21, 2003 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 don't want to save what I inserted. Anybody know the command? Thanks Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Mike_R Posted November 1, 2003 Posted November 1, 2003 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, I'll 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: xlApp.DisplayAlerts = False xlApp.Quit xlApp = Nothing (2) Close your Workbook without saving changes: 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! 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 didn't want, but for completeness: xlWB.SaveAs("C:\My Documents\Book1.xls") xlApp.Quit xlApp = Nothing Hope this helps... :), Mike Quote Posting Guidelines Avatar by Lebb
Recommended Posts