By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Excel Process still running

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You need to insert a exWorkBook.Close() statement before exWorkBook =
Nothing.

Mike Ober.
"Mike Eaton" <Mi*******@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
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

Nov 20 '05 #2

P: n/a
It also helps if you use the following to release your com objects
System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApplication)

Use this to release all the com objects you used

"Mike Eaton" <Mi*******@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
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

Nov 20 '05 #3

P: n/a
Hi,

Dont forget to call GC.Collect.

System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApplication)
GC.Collect()

Ken
-----------------------
"Steve Flitcroft" <as*******@hotmail.com> wrote in message
news:en**************@TK2MSFTNGP12.phx.gbl...
It also helps if you use the following to release your com objects
System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApplication)

Use this to release all the com objects you used

"Mike Eaton" <Mi*******@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
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


Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.