BackgroundWorker and Office References

oprogrammer

Newcomer
Joined
Sep 17, 2008
Messages
2
I am using BackgroundWorker and create a reference to excel. Problem is I can not seem to release the reference. It still shows up in task manager and does not release until the application closes.

Any suggestions?
 
xlApp.Quit()
xlApp = Nothing

Normally this works, but I can not seem to get it to work with a new thread with backgroundworker.

Code Example 1:

This code within a module works. Viewing task manager excel starts and exits. I use this all the time.

Sub mExcelReport()
Dim xlApp as New Excel.Application
Dim xlSheet as New Excel.WorkSheet

xlApp.Workbooks.Add
xlSheet = xlApp.ActiveSheet

xlSheet.Range("A2").Value = "Hello"

xlApp.Quit()

xlApp = Nothing

End Sub


Code Example 2:

When I run it with Backgroundworker the Excel Reference does not release. Excel is still visible with tasks manager. This is causing issues when other process run.

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

mExcelReport()


End Sub

Sub mExcelReport()
Dim xlApp as New Excel.Application
Dim xlSheet as New Excel.WorkSheet

xlApp.Workbooks.Add
xlSheet = xlApp.ActiveSheet

xlSheet.Range("A2").Value = "Hello"

xlApp.Quit()

xlApp = Nothing

End Sub


Any ideas?
 
Back
Top