Save Excel file

  • Thread starter Thread starter shoa
  • Start date Start date
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
 
Shoa,
Why don't you test for the existing file and delete it before you do the
save.

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

I think this should do it

Greetz Peter
 
Back
Top