msellery Posted April 30, 2003 Posted April 30, 2003 Here is a code for a button on form1: Dim Xl As New Excel.Application() Dim Xlb As Excel.Workbook = Xl.Workbooks.Open("C:\Kk.xls") Dim Xls As Excel.Worksheet = CType(Xlb.Worksheets(1), Excel.Worksheet) TextBox1.Text = Xls.Cells(1, 1).value Xls.Cells(1, 1).Value = "Something new" Xlb.Save() Xlb.Close() Xl.Workbooks.Close() Xl.Quit() When I click that, everything works as planned, but EXCEL.EXE is still a running process. The result is that you can not open Kk.xls through excel until my program is ended entirely. The problem with this is if my program crashes or ends by any other method other than the END command, Excel is still running and keeping that file in use. How do I completely shut down Excel after running the above code? Quote
Liqdfire Posted April 30, 2003 Posted April 30, 2003 Try using the ApplicaitonClass ie: Dim Xl As New Excel.ApplicationClass() Quote
msellery Posted April 30, 2003 Author Posted April 30, 2003 Thanks, but Excel.EXE is still running after that code executes. Any other possibilities? Quote
tylee Posted June 4, 2003 Posted June 4, 2003 I know this might be a bit of overkill but i got this to work in .net with it opening the excel file writing the value "Something New" and then closing it ( and destorying the Excel process in the task manager) Hope this works for you Dim Xl As New Excel.Application() Dim Xlb As Excel.Workbook = Xl.Workbooks.Open("C:\Kk.xls") Dim Xls As Excel.Worksheet = CType(Xlb.Worksheets(1), Excel.Worksheet) TextBox1.Text = Xls.Cells(1, 1).value Xls.Cells(1, 1).Value = "Something new" Xlb.Save() 'Changed Code exWorkbook.Close() exObj.Workbooks.Close() exObj.Application.Quit() exObj.Quit() exWorksheet = Nothing exWorkbook = Nothing exObj = Nothing GC.Collect() GC.WaitForPendingFinalizers() Quote
Recommended Posts