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?