mainrotor
asked on
I need help working with Excel in VB.Net
Hi Experts,
I have the following code which generates and saves an Excel spreadsheet from my VB.Net application.
1) How can I make it so Excel saves the file without prompting me that there already is an Existing file with the same name (I want it to overwrite the file if it already exists)?
2) How can I open the file (i.e. make it visible after it has been saved)?
Thanks in advance,
mrotor
I have the following code which generates and saves an Excel spreadsheet from my VB.Net application.
1) How can I make it so Excel saves the file without prompting me that there already is an Existing file with the same name (I want it to overwrite the file if it already exists)?
2) How can I open the file (i.e. make it visible after it has been saved)?
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
'SOME DATA PROCESSING ...
xlWorkBook.SaveAs("c:\Transactions.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, _
Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue)
xlWorkBook.Close(True, misValue, misValue)
xlApp.Quit()
Thanks in advance,
mrotor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) System.IO.File.Delete(file
2) myProcess = Process.Start("excel.exe /r book1.xlsx");