473,228 Members | 1,840 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,228 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 2137
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.