Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
  • 2 weeks later...
Posted

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

Posting Guidelines

 

Avatar by Lebb

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...