Excel Server Object won't overwrite

  • Thread starter Thread starter Olivia Towery
  • Start date Start date
O

Olivia Towery

I am using the CreateObject("Excel.Application") to create a workbook from
three separate tables in a sql db. This works great and compiles three
separate sheets to one workbook. The following lines name and add the
workbook to the directory:

fName = "" & strfile & ".xls"

xls.ActiveWorkbook.SaveAs server.MapPath(".") & "\" & fName
xls.Application.Quit

What do I need to add to make the object overwrite the existing file?
 
you have a line like:

set xls = createobject("excel.application")
(Or its equivalent)

xls.displayalerts = false
'your code to save/overwrite
xls.displayalerts = true

(Do you actually need the .application in xls.application.quit??)
 
Olivia said:
I am using the CreateObject("Excel.Application") to create a workbook
from three separate tables in a sql db. This works great and
compiles three separate sheets to one workbook. The following lines
name and add the workbook to the directory:

fName = "" & strfile & ".xls"

xls.ActiveWorkbook.SaveAs server.MapPath(".") & "\" & fName
xls.Application.Quit

What do I need to add to make the object overwrite the existing file?


You could avoid the overwite by using FSO to explicitly check for the
existence of the file to be overwitten first and delete it if it exits
before calling the SaveAs method.
 

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

Back
Top