Link to home
Start Free TrialLog in
Avatar of mainrotor
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)?


        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()

Open in new window


Thanks in advance,
mrotor
Avatar of Jason Schlueter
Jason Schlueter
Flag of United States of America image

Maybe something like this?

1) System.IO.File.Delete(filename) before save.
2) myProcess = Process.Start("excel.exe /r book1.xlsx");
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial