Save Excel file

S

shoa

Hello all

I open a template Excel file as following
-----------------------------
im xlApp As Object

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.Worksheet

xlApp = CreateObject("Excel.Application")

xlApp.Visible = True

xlBook = xlApp.Workbooks.Open("C:\Database\TempExcel\invoice.xls")

xlSheet = xlBook.Worksheets(1)

---------------

Then I save this file as with a new name

Dim fileName As String = "C:\aNewFile.xls"

xlBook.SaveAs(fileName)

-------------

However, if there is existed file "aNewFile.xls", there is a message
informing that there is a file with the same name and ask me if I want to
replace it. I do not want to have this message and want my application
automatically replaces the old file. Coul you please tell me how to do that.

Thank you very much for your help

S.Hoa
 
D

Doug Bell

Shoa,
Why don't you test for the existing file and delete it before you do the
save.

Doug
 
P

Peter Proost

With xlApp
.DisplayAlerts = False
xlBook.SaveAs("C:\aNewFile.xls")
.DisplayAlerts = True
End With

I think this should do it

Greetz Peter
 

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