473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2144
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
6
by: Steve Richter | last post by:
I am getting error in a vbscript: ActiveX component cant create object: Excel.Application. The vbscript code is: Dim objExcel Set objExcel = CreateObject("Excel.Application") I am pretty...
8
by: jack | last post by:
Access is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it...
12
by: D. Shane Fowlkes | last post by:
This most likely belongs in another forum but I thought I'd start here. I have a COM Object written in VB6. The DLL will access MS Excel and use it's Object Library to write a customized report...
3
by: Carlos Magalhaes | last post by:
Hey All, I am doing some excel automation using the excel COM. I can do most of the functions and its working well until I come across a formula. I can run a formula and insert the formula...
3
by: Mitchell Vincent | last post by:
Does anyone have some good examples of Excel automation with (VB).NET? I have some Excel spreadsheets that a customer needs parsed out but I've never tried to use Excel programatically before! ...
6
by: a.theil | last post by:
Please help! I need a simple excel automation, just 2 write some files into excel. I do: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As...
5
by: RJN | last post by:
Hi I'm invoking the excel object from ASP.Net application. My development machine is Windows 2000 and MS Office is installed on my m/c. I have added reference to the Excel COM object, I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.