470,849 Members | 1,067 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Excel does not die using automation

I have a vb.net app that opens an excel worksheet, reads data and then closes
the sheet. Im noticing that the Excel process is still running after I have
closed and disposed of my excel objects.

The following code (Test1) demonstrates the essence of what I am doing.
When I check the processes while ruinning the method, I notice that the Excel
process remains after exiting the sub (and until I exit the application)

Sub Test1
Dim objExcelApp As New Excel.Application

Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet = objExcelWorkBook.Sheets(1)

Dim objRange As Excel.Range
objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)
''http://www.vbforums.com/archive/index.php/t-396405.html
objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook.Close()
objExcelWorkBook = Nothing
objExcelApp.Workbooks.Close()
objExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process is
created on line
Dim objExcelApp As New Excel.Application
and killed on line
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
Dim objExcelApp As New Excel.Application

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing
End Sub
What is it that is keeping a reference to the Excel process and how do I
kill the process?
Jul 6 '08 #1
7 1986
You must call ReleaseComObject(obj) on EACH COM object you've created.

That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc.
objects one might instantiate within the Excel.Application.

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:9B**********************************@microsof t.com...
>I have a vb.net app that opens an excel worksheet, reads data and then
closes
the sheet. Im noticing that the Excel process is still running after I
have
closed and disposed of my excel objects.

The following code (Test1) demonstrates the essence of what I am doing.
When I check the processes while ruinning the method, I notice that the
Excel
process remains after exiting the sub (and until I exit the application)

Sub Test1
Dim objExcelApp As New Excel.Application

Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)

Dim objRange As Excel.Range
objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)
''http://www.vbforums.com/archive/index.php/t-396405.html
objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook.Close()
objExcelWorkBook = Nothing
objExcelApp.Workbooks.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process is
created on line
Dim objExcelApp As New Excel.Application
and killed on line

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
Dim objExcelApp As New Excel.Application
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing
End Sub
What is it that is keeping a reference to the Excel process and how do I
kill the process?

Jul 6 '08 #2
Using the following as test code, the Excel process remains. Can you see a
reason for this?

Sub Test
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet = objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)

objExcelWorkBook.Close()
objExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing
End Sub
"Scott M." wrote:
You must call ReleaseComObject(obj) on EACH COM object you've created.

That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc.
objects one might instantiate within the Excel.Application.

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:9B**********************************@microsof t.com...
I have a vb.net app that opens an excel worksheet, reads data and then
closes
the sheet. Im noticing that the Excel process is still running after I
have
closed and disposed of my excel objects.

The following code (Test1) demonstrates the essence of what I am doing.
When I check the processes while ruinning the method, I notice that the
Excel
process remains after exiting the sub (and until I exit the application)

Sub Test1
Dim objExcelApp As New Excel.Application

Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)

Dim objRange As Excel.Range
objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)
''http://www.vbforums.com/archive/index.php/t-396405.html
objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook.Close()
objExcelWorkBook = Nothing
objExcelApp.Workbooks.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process is
created on line
Dim objExcelApp As New Excel.Application
and killed on line

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
Dim objExcelApp As New Excel.Application
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing
End Sub
What is it that is keeping a reference to the Excel process and how do I
kill the process?


Jul 6 '08 #3
Are you checking to see if Excel is running when you are debugging your code
in Visual Studio?

If so, you shouldn't as this isn't going to give you an accurate
representation of processes. When I compile your code into an .exe and run
that .exe directly with Task Manager open, Excel comes up and then drops off
the list after my method call to do the Excel stuff finishes and my console
sits open waiting for input via a Console.Read.

-Scott

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:29**********************************@microsof t.com...
Using the following as test code, the Excel process remains. Can you see
a
reason for this?

Sub Test
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)

objExcelWorkBook.Close()
objExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing
End Sub
"Scott M." wrote:
>You must call ReleaseComObject(obj) on EACH COM object you've created.

That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc.
objects one might instantiate within the Excel.Application.

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:9B**********************************@microso ft.com...
>I have a vb.net app that opens an excel worksheet, reads data and then
closes
the sheet. Im noticing that the Excel process is still running after I
have
closed and disposed of my excel objects.

The following code (Test1) demonstrates the essence of what I am doing.
When I check the processes while ruinning the method, I notice that the
Excel
process remains after exiting the sub (and until I exit the
application)

Sub Test1
Dim objExcelApp As New Excel.Application

Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)

Dim objRange As Excel.Range
objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)
''http://www.vbforums.com/archive/index.php/t-396405.html
objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook.Close()
objExcelWorkBook = Nothing
objExcelApp.Workbooks.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process is
created on line
Dim objExcelApp As New Excel.Application
and killed on line

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
Dim objExcelApp As New Excel.Application
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing
End Sub
What is it that is keeping a reference to the Excel process and how do
I
kill the process?



Jul 7 '08 #4
I was doing this in debug mode. I have done as you suggested and run the
compiled exe (winforms). The excel process is still running after executing
the code. The process is only killed when the form is closed. I have no
other code on this form other than a button_click event to execute the code.

I then tried the same thing as console app as you have done and in my case
the excel process is running until the console window closes

Imports Microsoft.Office.Interop

Module Module1

Sub Main()
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet = objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
Console.WriteLine(objRange.Text)
'Console.Read()
objExcelWorkBook.Close()
objExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing

Console.WriteLine("Waiting")
Console.Read()
End Sub

End Module
"Scott M." wrote:
Are you checking to see if Excel is running when you are debugging your code
in Visual Studio?

If so, you shouldn't as this isn't going to give you an accurate
representation of processes. When I compile your code into an .exe and run
that .exe directly with Task Manager open, Excel comes up and then drops off
the list after my method call to do the Excel stuff finishes and my console
sits open waiting for input via a Console.Read.

-Scott

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:29**********************************@microsof t.com...
Using the following as test code, the Excel process remains. Can you see
a
reason for this?

Sub Test
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)

objExcelWorkBook.Close()
objExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing
End Sub
"Scott M." wrote:
You must call ReleaseComObject(obj) on EACH COM object you've created.

That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc.
objects one might instantiate within the Excel.Application.

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:9B**********************************@microsof t.com...
I have a vb.net app that opens an excel worksheet, reads data and then
closes
the sheet. Im noticing that the Excel process is still running after I
have
closed and disposed of my excel objects.

The following code (Test1) demonstrates the essence of what I am doing.
When I check the processes while ruinning the method, I notice that the
Excel
process remains after exiting the sub (and until I exit the
application)

Sub Test1
Dim objExcelApp As New Excel.Application

Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)

Dim objRange As Excel.Range
objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)
''http://www.vbforums.com/archive/index.php/t-396405.html
objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook.Close()
objExcelWorkBook = Nothing
objExcelApp.Workbooks.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process is
created on line
Dim objExcelApp As New Excel.Application
and killed on line

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
Dim objExcelApp As New Excel.Application
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing
End Sub
What is it that is keeping a reference to the Excel process and how do
I
kill the process?


Jul 7 '08 #5
What version of .NET are you using? Excel closes in my console app when I
try.
"Terry Holland" <MS***********@nospam.nospamwrote in message
news:BE**********************************@microsof t.com...
>I was doing this in debug mode. I have done as you suggested and run the
compiled exe (winforms). The excel process is still running after
executing
the code. The process is only killed when the form is closed. I have no
other code on this form other than a button_click event to execute the
code.

I then tried the same thing as console app as you have done and in my case
the excel process is running until the console window closes

Imports Microsoft.Office.Interop

Module Module1

Sub Main()
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
Console.WriteLine(objRange.Text)
'Console.Read()
objExcelWorkBook.Close()
objExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing

Console.WriteLine("Waiting")
Console.Read()
End Sub

End Module
"Scott M." wrote:
>Are you checking to see if Excel is running when you are debugging your
code
in Visual Studio?

If so, you shouldn't as this isn't going to give you an accurate
representation of processes. When I compile your code into an .exe and
run
that .exe directly with Task Manager open, Excel comes up and then drops
off
the list after my method call to do the Excel stuff finishes and my
console
sits open waiting for input via a Console.Read.

-Scott

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:29**********************************@microso ft.com...
Using the following as test code, the Excel process remains. Can you
see
a
reason for this?

Sub Test
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)

objExcelWorkBook.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing
End Sub
"Scott M." wrote:

You must call ReleaseComObject(obj) on EACH COM object you've created.

That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc.
objects one might instantiate within the Excel.Application.

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:9B**********************************@microso ft.com...
I have a vb.net app that opens an excel worksheet, reads data and
then
closes
the sheet. Im noticing that the Excel process is still running
after I
have
closed and disposed of my excel objects.

The following code (Test1) demonstrates the essence of what I am
doing.
When I check the processes while ruinning the method, I notice that
the
Excel
process remains after exiting the sub (and until I exit the
application)

Sub Test1
Dim objExcelApp As New Excel.Application

Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)

Dim objRange As Excel.Range
objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)
''http://www.vbforums.com/archive/index.php/t-396405.html
objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook.Close()
objExcelWorkBook = Nothing
objExcelApp.Workbooks.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process
is
created on line
Dim objExcelApp As New Excel.Application
and killed on line

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
Dim objExcelApp As New Excel.Application
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing
End Sub
What is it that is keeping a reference to the Excel process and how
do
I
kill the process?



Jul 7 '08 #6
im using .net 2.0

"Scott M." wrote:
What version of .NET are you using? Excel closes in my console app when I
try.
"Terry Holland" <MS***********@nospam.nospamwrote in message
news:BE**********************************@microsof t.com...
I was doing this in debug mode. I have done as you suggested and run the
compiled exe (winforms). The excel process is still running after
executing
the code. The process is only killed when the form is closed. I have no
other code on this form other than a button_click event to execute the
code.

I then tried the same thing as console app as you have done and in my case
the excel process is running until the console window closes

Imports Microsoft.Office.Interop

Module Module1

Sub Main()
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
Console.WriteLine(objRange.Text)
'Console.Read()
objExcelWorkBook.Close()
objExcelApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing

Console.WriteLine("Waiting")
Console.Read()
End Sub

End Module
"Scott M." wrote:
Are you checking to see if Excel is running when you are debugging your
code
in Visual Studio?

If so, you shouldn't as this isn't going to give you an accurate
representation of processes. When I compile your code into an .exe and
run
that .exe directly with Task Manager open, Excel comes up and then drops
off
the list after my method call to do the Excel stuff finishes and my
console
sits open waiting for input via a Console.Read.

-Scott

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:29**********************************@microsof t.com...
Using the following as test code, the Excel process remains. Can you
see
a
reason for this?

Sub Test
Dim objExcelApp As New Excel.Application
Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)
Dim objRange As Excel.Range

objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)

objExcelWorkBook.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objRange)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorksheet)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelWorkBook)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook = Nothing
objExcelApp = Nothing
End Sub
"Scott M." wrote:

You must call ReleaseComObject(obj) on EACH COM object you've created.

That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc.
objects one might instantiate within the Excel.Application.

"Terry Holland" <MS***********@nospam.nospamwrote in message
news:9B**********************************@microsof t.com...
I have a vb.net app that opens an excel worksheet, reads data and
then
closes
the sheet. Im noticing that the Excel process is still running
after I
have
closed and disposed of my excel objects.

The following code (Test1) demonstrates the essence of what I am
doing.
When I check the processes while ruinning the method, I notice that
the
Excel
process remains after exiting the sub (and until I exit the
application)

Sub Test1
Dim objExcelApp As New Excel.Application

Dim objExcelWorkBook As Excel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
Dim objExcelWorksheet As Excel.Worksheet =
objExcelWorkBook.Sheets(1)

Dim objRange As Excel.Range
objRange = objExcelWorksheet.Range("A1")
MsgBox(objRange.Text)
''http://www.vbforums.com/archive/index.php/t-396405.html
objRange = Nothing
objExcelWorksheet = Nothing
objExcelWorkBook.Close()
objExcelWorkBook = Nothing
objExcelApp.Workbooks.Close()
objExcelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process
is
created on line
Dim objExcelApp As New Excel.Application
and killed on line

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
Dim objExcelApp As New Excel.Application
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

objExcelApp = Nothing
End Sub
What is it that is keeping a reference to the Excel process and how
do
I
kill the process?



Jul 7 '08 #7
On Jul 6, 1:53*pm, Terry Holland <MSDNNospam...@nospam.nospamwrote:
I have a vb.net app that opens anexcelworksheet, reads data and then closes
the sheet. *Im noticing that theExcelprocess is still running after I have
closed and disposed of myexcelobjects.

The following code (Test1) demonstrates the essence of what I am doing. *
When I check the processes while ruinning the method, I notice that theExcel
process remains after exiting the sub (and until I exit the application)

Sub Test1
* * * * * *Dim objExcelApp As NewExcel.Application

* * * * Dim objExcelWorkBook AsExcel.Workbook =
objExcelApp.Workbooks.Open("C:\Test.xls")
* * * * Dim objExcelWorksheet AsExcel.Worksheet = objExcelWorkBook.Sheets(1)

* * * * Dim objRange AsExcel.Range
* * * * objRange = objExcelWorksheet.Range("A1")
* * * * MsgBox(objRange.Text)
* * * * ''http://www.vbforums.com/archive/index.php/t-396405.html
* * * * objRange = Nothing
* * * * objExcelWorksheet = Nothing
* * * * objExcelWorkBook.Close()
* * * * objExcelWorkBook = Nothing
* * * * objExcelApp.Workbooks.Close()
* * * * objExcelApp.Quit()

* * * * System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

* * * * objExcelApp = Nothing

End Sub

When I strip the code dow to this (Test2) I notice that the process is
created on line
* * * * *Dim objExcelApp As NewExcel.Application
and killed on line
* * * * System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

Sub Test2
* * * * Dim objExcelApp As NewExcel.Application

* * * * System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcelApp)

* * * * objExcelApp = Nothing
End Sub

What is it that is keeping a reference to theExcelprocess and how do I
kill the process?
I don't know if it works for you, but if you have small workbooks you
can use
our GemBox.Spreadsheet Free (http://www.gemboxsoftware.com/
GBSpreadsheetFree.htm)
Excel component for XLS/CSV/XLSX reading/writing/reporting.
Automation has many issues: http://www.gemboxsoftware.com/GBSpre...htm#Automation

--Zeljko
Jul 7 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Mansi | last post: by
6 posts views Thread by Steve Richter | last post: by
8 posts views Thread by jack | last post: by
12 posts views Thread by D. Shane Fowlkes | last post: by
3 posts views Thread by Carlos Magalhaes | last post: by
3 posts views Thread by Mitchell Vincent | last post: by
6 posts views Thread by a.theil | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.