How to avoid dialogue box while saveas an Excel file in VB.Net

M

michaellm

Hi ALL,
In VB.Net,
I create an Excel as followed:
Dim excelapp As New Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet

' Get a new workbook.
oWB = excelapp.Workbooks.Add
oSheet = CType(oWB.ActiveSheet, Excel.Worksheet)
Dim i As Integer
For i = 0 To 100
oSheet.Range("A" & (i + 1).ToString).Value = i
oSheet.Range("B" & (i + 1).ToString).Formula = "=A" & (i +
1).ToString
Next
oSheet.SaveAs("C:\Test.xls")
While saving the new fiel, if the file "Test.xls" already exists, a
dialogue box will pop up asking if overwrite that file. However, I
don't want to see this box, I want to just overwrite that file. How
should I do then?
Thanksï¼
 
G

Guest

Try

excelapp.DisplayAlerts = False
oSheet.SaveAs("C:\Test.xls")
excelapp.DisplayAlerts = True

Kim
 

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