Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


How to get SaveAs to Close Excel without Warning Dialog

Keywords:   saveas

Question:

I have the following code to save and close Excel, but a window comes up asking if I want to overwrite the currently existing file.

How do I get rid of that window?

DB             = ObjectOpen("Excel.Application")
DB.DisplayAlerts =@FALSE	; this prevents the warning message from coming up
oAPP = DB.Workbooks
oAPP.Open("C:\WINDOWS\DESKTOP\test.XLS")
oWKS = DB.Worksheets
oWS  = DB.Worksheets(1)
oWS.Activate
oWS.SaveAs(:: Filename="C:\WINDOWS\DESKTOP\test.XLS") ;note the oWS object here
oAPP.close()
ObjectClose(DB)
exit

Answer:

Set the method, "DisplayAlerts", on the main OLE object, to FALSE, e.g.,
DB             = ObjectOpen("Excel.Application")
DB.DisplayAlerts =@FALSE	; this prevents the warning message from coming up
oAPP = DB.Workbooks
oAPP.Open("C:\WINDOWS\DESKTOP\test.XLS")
oWKS = DB.Worksheets
oWS  = DB.Worksheets(1)
oWS.Activate
oWS.SaveAs(:: Filename="C:\WINDOWS\DESKTOP\test.XLS") ;note the oWS object here
oAPP.close()
ObjectClose(DB)

Article ID:   W14696
Filename:   Get SaveAs to Close without Alert Box.txt