Closing Excel from Script

G

Guest

Since my high powered data analysis programming language doesn't seem to want
to play nice with Excel (where I want the data to go) I'm having to resort to
using a vbscript to act as a bridge between the two. In this script, after
the macro runs I want Excel to close down and not save. However, when it
closes it prompts me on whether I want to save or not. Is there a way to
have Excel not put up the prompt and close without saving? Thanks

Option Explicit
Dim objXL

Set objXL = WScript.CreateObject("Excel.Application")
objXL.WorkBooks.Open "\\Inmrc\irs\temp\Reports.xls"
objXL.Visible = TRUE ' Optional
objXL.Run("LoadData")
objXL.Quit
Set objXL = Nothing
 
G

Guest

Not sure if this would work in the "program" that you have, but Excel has two
things that it "checks" prior to closing.

If the SAVED property is set to TRUE then it will not ask to save the
document and also will not save the document
The other is the DisplayAlerts property. If it is set to FALSE then when
closing it will not question to save, and will not save.

So I *think* that
objXL.Saved = TRUE
or
objXL.DisplayAlerts = FALSE

would work, but I am not sure which will work.

DisplayAlerts is an application item where Saved relates directly to the
workbook. objXL looks like it may be an application object, so DisplayAlerts
may have to be the path you go with.
 
G

Guest

VBScript came back saying that objXL.Saved was not a supported property.
However, the objXL.DisplayAlerts = FALSE seemed to do the trick.
Thanks
 

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

Top