Shutting down Excel in VB.net
Final problem (I think).
I have successfully loaded and updated and save an Excel spreadsheet in VB.net. But when I close down Excel as follows:
If txtSave.Text = "Y" Then
xlWb.Save()
xlWb.Close(False)
Else
xlWb.Close(False)
End If
xlWs = Nothing 'Sheet
xlWb = Nothing 'Workbook
xlApp.Quit()
xlApp = Nothing 'Application
According to the Task Manager, Excel is still running in the background. If I run the test enough times, I run out of memory due to multiple versions running in the background. I have to go into the Task Manager and "End Task" for each one.
I've looked everywhere to find out how people get it 'all' closed and can't find the correct answer although I have tried several suggestions.
Any help would be appreciated.
Re: Shutting down Excel in VB.net
Try this...
Code:
If txtSave.Text = "Y" Then
xlWb.Save()
End If
xlWb.Close(False)
Marshal.ReleaseComObject(xlWb)
xlWs = Nothing 'Sheet
xlWb = Nothing 'Workbook
xlApp.Quit()
Marshal.ReleaseComObject(xlApp)
xlApp = Nothing 'Application
Re: Shutting down Excel in VB.net
Code:
Imports System.Runtime.InteropServices
Re: Shutting down Excel in VB.net
Quote:
Originally Posted by
.paul.
Try this...
Code:
If txtSave.Text = "Y" Then
xlWb.Save()
End If
xlWb.Close(False)
Marshal.ReleaseComObject(xlWb)
xlWs = Nothing 'Sheet
xlWb = Nothing 'Workbook
xlApp.Quit()
Marshal.ReleaseComObject(xlApp)
xlApp = Nothing 'Application
Works better. Only leaves one instance of Excel running in the background. It used to be two. Don't know why 2 but now is only one with the Marshal. line.
Re: Shutting down Excel in VB.net
I'll need to see the relevant code to help with that problem. There's nothing in your code snippet that suggests you have two instances of Excel...