closing excel (i know i know...)
i know this is a big problem for a lot of people and there are posts everywhere... but they aren't helping lol.
below, should this complete and close and terminate excel correctly? or am i missing something...
Code:
oExcel = CreateObject("Excel.Application")
oBooks = oExcel.Workbooks
oBook = oBooks.Open(Filename:="C:\Jared FC Project Desktop\fixture tracking.xls", UpdateLinks:=False, ReadOnly:=False)
oSheet = oBook.Worksheets(1)
oExcel.Visible = True
oSheet = Nothing
oBook.Close()
oBook = Nothing
oBooks.Close()
oBooks = Nothing
oExcel.Quit()
oExcel = Nothing
Re: closing excel (i know i know...)
I'll still throw in ReleaseComObject here :
Code:
xlbook.Close
'...do the same as the following for range references if any, and all the excel stuff you've used...
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws) 'the worksheet
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlbook) 'the workbook
xlapp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlapp) 'the application
Re: closing excel (i know i know...)
Re: closing excel (i know i know...)
Quote:
Originally Posted by
MarMan
What does it do?
I'm glad you asked. It so happens that MSDN has all the answers ;)
Quote:
This method is used to explicitly control the lifetime of a COM object used from managed code. You should use this method to free the underlying COM object that holds references to resources in a timely manner or when objects must be freed in a specific order.
More info in the link
Then you can look up the documentation for the .Close method and see what the differences are.
Re: closing excel (i know i know...)
well i haven't tried the code provided (im about to)
currently the excel process is still in task manager .... (yeah that crappy problem)
Re: closing excel (i know i know...)
after the code below... the process still remains in task manager :(
Code:
oExcel = CreateObject("Excel.Application")
oBooks = oExcel.Workbooks
oBook = oBooks.Open(Filename:="C:\Jared FC Project Desktop\fixture tracking.xls", UpdateLinks:=False, ReadOnly:=False)
oSheet = oBook.Worksheets(1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet) 'the worksheet
oBook.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook) 'the workbook
oBook = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel) 'the application
oExcel = Nothing
Re: closing excel (i know i know...)
You could try killing the process:
Code:
For Each p As Process In Process.GetProcessesByName("excel")
p.Kill()
Next
Though that would close excel if the user had it running.