I have the same problem.
I have tried lots of things and just couldn't get it to quit.
I think one of my references may not be the correct style and is forcing
Excel to stay open but for the life of me I can't see it.
Anyone want to try?
Public Sub Export2Excel(By Val dt As DataTable, ByVal strPath As String,
ByRef pb As ProgressBar, ByVal MyOption As String)
'add reference to Microsoft Excel
Dim objXL As Excel.Applicati on
Dim objWBS As Excel.Workbooks
Dim objWB As Excel.Workbook
Dim objWS As Excel.Worksheet
'get a running instance of Excel - this minimizes the number of instances of
Excel in memory!
objXL = CType(GetObject (, "Excel.Applicat ion"), Excel.Applicati on)
'create a new instance of Excel if there isn't one running.
'objXL = New Excel.Applicati on
objWBS = objXL.Workbooks
objWB = objWBS.Add
objWS = CType(objWB.Wor ksheets(1), Excel.Worksheet )
'do stuff here
objWB.Close()
'problem - Excel is staying in Memory even after the Quit. It goes
away when the form is closed.
'Limited to 1 instance stuck in memory instead of unlimited number.
System.Runtime. InteropServices .Marshal.Releas eComObject(objW S)
System.Runtime. InteropServices .Marshal.Releas eComObject(objW B)
System.Runtime. InteropServices .Marshal.Releas eComObject(objW BS)
objXL.Quit()
System.Runtime. InteropServices .Marshal.Releas eComObject(objX L)
'this does not work to clear out the Excel instance from memory. Even though
it looks like "just the thing".
'http://www.dotnetinter op.com/faq/?q=OfficeCleanu p
'http://support.microso ft.com/default.aspx?sc id=kb;en-us;317109
'release other objects too! Still does not work. May be the remote call
issue.
objWS = Nothing
objWB = Nothing
objWBS = Nothing
objXL = Nothing
'this does not work to clear out the Excel instance from memory either.
GC.Collect()
GC.WaitForPendi ngFinalizers()
End Sub
--
Joe Fallon
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:eK******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
Use this around your .quit code:
Marshal.Release ComObject(objws )
objxl.Quit()
Marshal.Release ComObject(objxl )
HTH,
Bernie Yaeger
"Wenke Ji" <a1****@motolor a.com> wrote in message
news:04******** *************** *****@phx.gbl.. . Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("E XCEL.Applicatio n")
Set TargetWorkbook = ExcelServer.Wor kbooks.Open
(CurrentBook)
Befor the programm exit , I use the below API:
TargetWorkbook. Save
TargetWorkbook. Close
But I check the "Task Management" , the Excel is still at
list.
How can I close the EXCEL automation server completely in
VB program?
Thanks!
BRs
Wenke