Excel Process still running

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I'm working on an application that opens an excel workbook, does some processing on the data contained in it, and then saves the data into the workbook. What I'm noticing is that once I'm done working with the workbook and have freed all the object references to the excel application, I still have an 'Excel' process running (when I look under 'Processes' in the Windows Task List).

Is there something I'm not cleaning up properly? Suggestions are greatly appreciated.

Here's what I'm doing:
Dim exApplication As Excel.Application
Dim exWorkBook As Excel.Workbook
Dim exWorkSheet As Excel.Worksheet
Try
exApplication = New Excel.Application
exWorkBook = exApplication.Workbooks.Open(fiSource.FullName)
exWorkSheet = exWorkBook.Worksheets(SHEET_NAME)
Dim iCount As Integer = 0
For r As Integer = 2 To MAX_CARDS
Dim strName As String = exWorkSheet.Cells(r, 1).value
If (strName Is Nothing) Then
Exit For
Else
.. do some stuff to the worksheet...
End If
Next
exWorkBook.Save()
Catch ex As Exception
MsgBox("There was an error accessing the Excel spreadsheet:" + vbCrLf + ex.ToString, MsgBoxStyle.Exclamation, Me.Text)
Finally
exWorkSheet = Nothing
exWorkBook = Nothing
exApplication.Quit()
exApplication = Nothing
End Try
 
You need to insert a exWorkBook.Close() statement before exWorkBook =
Nothing.

Mike Ober.


Mike Eaton said:
Hi there,

I'm working on an application that opens an excel workbook, does some
processing on the data contained in it, and then saves the data into the
workbook. What I'm noticing is that once I'm done working with the workbook
and have freed all the object references to the excel application, I still
have an 'Excel' process running (when I look under 'Processes' in the
Windows Task List).
Is there something I'm not cleaning up properly? Suggestions are greatly appreciated.

Here's what I'm doing:
Dim exApplication As Excel.Application
Dim exWorkBook As Excel.Workbook
Dim exWorkSheet As Excel.Worksheet
Try
exApplication = New Excel.Application
exWorkBook = exApplication.Workbooks.Open(fiSource.FullName)
exWorkSheet = exWorkBook.Worksheets(SHEET_NAME)
Dim iCount As Integer = 0
For r As Integer = 2 To MAX_CARDS
Dim strName As String = exWorkSheet.Cells(r, 1).value
If (strName Is Nothing) Then
Exit For
Else
.. do some stuff to the worksheet...
End If
Next
exWorkBook.Save()
Catch ex As Exception
MsgBox("There was an error accessing the Excel
spreadsheet:" + vbCrLf + ex.ToString, MsgBoxStyle.Exclamation, Me.Text)
 
It also helps if you use the following to release your com objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(exApplication)

Use this to release all the com objects you used

Mike Eaton said:
Hi there,

I'm working on an application that opens an excel workbook, does some
processing on the data contained in it, and then saves the data into the
workbook. What I'm noticing is that once I'm done working with the workbook
and have freed all the object references to the excel application, I still
have an 'Excel' process running (when I look under 'Processes' in the
Windows Task List).
Is there something I'm not cleaning up properly? Suggestions are greatly appreciated.

Here's what I'm doing:
Dim exApplication As Excel.Application
Dim exWorkBook As Excel.Workbook
Dim exWorkSheet As Excel.Worksheet
Try
exApplication = New Excel.Application
exWorkBook = exApplication.Workbooks.Open(fiSource.FullName)
exWorkSheet = exWorkBook.Worksheets(SHEET_NAME)
Dim iCount As Integer = 0
For r As Integer = 2 To MAX_CARDS
Dim strName As String = exWorkSheet.Cells(r, 1).value
If (strName Is Nothing) Then
Exit For
Else
.. do some stuff to the worksheet...
End If
Next
exWorkBook.Save()
Catch ex As Exception
MsgBox("There was an error accessing the Excel
spreadsheet:" + vbCrLf + ex.ToString, MsgBoxStyle.Exclamation, Me.Text)
 
Hi,

Dont forget to call GC.Collect.

System.Runtime.InteropServices.Marshal.ReleaseComObject(exApplication)
GC.Collect()

Ken
-----------------------
It also helps if you use the following to release your com objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(exApplication)

Use this to release all the com objects you used

Mike Eaton said:
Hi there,

I'm working on an application that opens an excel workbook, does some
processing on the data contained in it, and then saves the data into the
workbook. What I'm noticing is that once I'm done working with the workbook
and have freed all the object references to the excel application, I still
have an 'Excel' process running (when I look under 'Processes' in the
Windows Task List).
Is there something I'm not cleaning up properly? Suggestions are greatly appreciated.

Here's what I'm doing:
Dim exApplication As Excel.Application
Dim exWorkBook As Excel.Workbook
Dim exWorkSheet As Excel.Worksheet
Try
exApplication = New Excel.Application
exWorkBook = exApplication.Workbooks.Open(fiSource.FullName)
exWorkSheet = exWorkBook.Worksheets(SHEET_NAME)
Dim iCount As Integer = 0
For r As Integer = 2 To MAX_CARDS
Dim strName As String = exWorkSheet.Cells(r, 1).value
If (strName Is Nothing) Then
Exit For
Else
.. do some stuff to the worksheet...
End If
Next
exWorkBook.Save()
Catch ex As Exception
MsgBox("There was an error accessing the Excel
spreadsheet:" + vbCrLf + ex.ToString, MsgBoxStyle.Exclamation, Me.Text)
 
Back
Top