G
Guest
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.Application, wb As Excel.Workboo
xl = CreateObject("Excel.application"
wb = xl.Workbooks.Ad
wb.Close(False
ReleaseCOMObject(wb
xl.Quit(
ReleaseCOMObject(xl
xl = Nothin
end su
sub foo_doesntwork(
Dim xl As Excel.Application, wb As Excel.Workboo
xl = CreateObject("Excel.application"
wb = xl.Workbooks.Ad
wb.Close(False
ReleaseCOMObject(wb
xl.Quit(
ReleaseCOMObject(xl
xl = Nothin
end su
Public Sub ReleaseCOMObject(ByVal pobj As Object
Dim x As Intege
Tr
x = System.Runtime.InteropServices.Marshal.ReleaseComObject(pobj
Catc
Finall
pobj = Nothin
End Tr
End Sub
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.Application, wb As Excel.Workboo
xl = CreateObject("Excel.application"
wb = xl.Workbooks.Ad
wb.Close(False
ReleaseCOMObject(wb
xl.Quit(
ReleaseCOMObject(xl
xl = Nothin
end su
sub foo_doesntwork(
Dim xl As Excel.Application, wb As Excel.Workboo
xl = CreateObject("Excel.application"
wb = xl.Workbooks.Ad
wb.Close(False
ReleaseCOMObject(wb
xl.Quit(
ReleaseCOMObject(xl
xl = Nothin
end su
Public Sub ReleaseCOMObject(ByVal pobj As Object
Dim x As Intege
Tr
x = System.Runtime.InteropServices.Marshal.ReleaseComObject(pobj
Catc
Finall
pobj = Nothin
End Tr
End Sub