Excel STILL running even when I use .quit()

msellery

Member
Joined
Mar 19, 2003
Messages
17
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?
 
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()
 
Back
Top