I don't know if this is in the right place but..
I am writing a VB.Net Class Library which uses Excel to produce workbooks
If I create an instance of Excel and then close it I can get .NET to destroy the instance of Excel, however as soon as I try to add a workbook and then end then close Excel the instance will not close
Code is included below
Has anyone else experienced this
What is going wrong
Sub foo_Works(
Dim xl As Excel.Applicati on, wb As Excel.Workboo
xl = CreateObject("E xcel.applicatio n"
wb = xl.Workbooks.Ad
wb.Close(False
ReleaseCOMObjec t(wb
xl.Quit(
ReleaseCOMObjec t(xl
xl = Nothin
end su
sub foo_doesntwork(
Dim xl As Excel.Applicati on, wb As Excel.Workboo
xl = CreateObject("E xcel.applicatio n"
wb = xl.Workbooks.Ad
wb.Close(False
ReleaseCOMObjec t(wb
xl.Quit(
ReleaseCOMObjec t(xl
xl = Nothin
end su
Public Sub ReleaseCOMObjec t(ByVal pobj As Object
Dim x As Intege
Tr
x = System.Runtime. InteropServices .Marshal.Releas eComObject(pobj
Catc
Finall
pobj = Nothin
End Tr
End Sub