ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Excel Server Object won't overwrite (https://www.excelbanter.com/excel-worksheet-functions/27165-excel-server-object-wont-overwrite.html)

Olivia Towery

Excel Server Object won't overwrite
 
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?

--
Olivia Towery



Dave Peterson

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 Towery wrote:

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?

--
Olivia Towery


--

Dave Peterson

Michael Harris \(MVP\)

Olivia Towery wrote:
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.


--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.





All times are GMT +1. The time now is 07:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com