views:

116

answers:

1

Can anyone help me on how can I overwrite the excel file without prompting the users in VB.Net..

I have try this code but It doesn't work..

Dim xlsApp As New Excel.Application
Dim xlsBook As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim dir As String = Application.StartupPath & "\Template\SampleTemplate.xls"
xlsBook = GetObject(dir)
xlsSheet = xlsBook.Sheets("Per BPA Error Report")


xlsSheet.Range("C2:T2").Merge()

xlsApp.DisplayAlerts = False
xlsSheet.SaveAs(Application.StartupPath & "\Template\SampleTemplate.xls")
xlsBook = Nothing
xlsSheet = Nothing
xlsApp.Quit()
A: 

If you just want to overwrite the file that's currently there, might just be easier to delete it first and then save the new file. So just use System.IO.File.Delete.

ho1
Thanks for your suggestion Mr. Ho
Mark