Unable to quit Excel OLE app from vb .net

M

Mike

Can anyone tell me why the following code fails to quit
Excel for me.

If I comment out the four lines that reference the
workbook, Excel closes.

excel = CreateObject("excel.application")
excelworkbook = excel.Workbooks.Open(in_file)
excelworkbook.close()
System.Runtime.InteropServices.Marshal.ReleaseComObject
(excelworkbook)
excelworkbook = Nothing
excel.quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject
(excel)
excel = Nothing

Thanks for any help.

Mike Sweet
 
M

Mike

In case anyone is interested, I stumbled upon the
answer. I must call two "garbage collection" lines at
the very end of the code:

GC.Collect()
GC.WaitForPendingFinalizers()

Boy, while vb .net might give you a little more power
than 6.0, it amazes me how difficult it is to do some
simple things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top