![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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.ReleaseComObject(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.ReleaseComObject(objExcelApp) Sub Test2 Dim objExcelApp As New Excel.Application System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objExcelApp = Nothing End Sub What is it that is keeping a reference to the Excel process and how do I kill the process? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Excel does not die using automation 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" <MSDNNospam248@xxxxxx> wrote in message news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@xxxxxx Quote: >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.ReleaseComObject(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.ReleaseComObject(objExcelApp) > > Sub Test2 > Dim objExcelApp As New Excel.Application > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > objExcelApp = Nothing > End Sub > > > What is it that is keeping a reference to the Excel process and how do I > kill the process? |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Excel does not die using automation 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.ReleaseComObject(objRange) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objRange = Nothing objExcelWorksheet = Nothing objExcelWorkBook = Nothing objExcelApp = Nothing End Sub "Scott M." wrote: Quote: > 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" <MSDNNospam248@xxxxxx> wrote in message > news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@xxxxxx Quote: > >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.ReleaseComObject(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.ReleaseComObject(objExcelApp) > > > > Sub Test2 > > Dim objExcelApp As New Excel.Application > > > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > objExcelApp = Nothing > > End Sub > > > > > > What is it that is keeping a reference to the Excel process and how do I > > kill the process? > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Excel does not die using automation 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" <MSDNNospam248@xxxxxx> wrote in message news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3@xxxxxx Quote: > 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.ReleaseComObject(objRange) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > objRange = Nothing > objExcelWorksheet = Nothing > objExcelWorkBook = Nothing > objExcelApp = Nothing > End Sub > "Scott M." wrote: > Quote: >> 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" <MSDNNospam248@xxxxxx> wrote in message >> news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@xxxxxx Quote: >> >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.ReleaseComObject(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.ReleaseComObject(objExcelApp) >> > >> > Sub Test2 >> > Dim objExcelApp As New Excel.Application >> > >> > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) >> > >> > objExcelApp = Nothing >> > End Sub >> > >> > >> > What is it that is keeping a reference to the Excel process and how do >> > I >> > kill the process? >> >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Excel does not die using automation 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.ReleaseComObject(objRange) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objRange = Nothing objExcelWorksheet = Nothing objExcelWorkBook = Nothing objExcelApp = Nothing Console.WriteLine("Waiting") Console.Read() End Sub End Module "Scott M." wrote: Quote: > 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" <MSDNNospam248@xxxxxx> wrote in message > news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3@xxxxxx Quote: > > 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.ReleaseComObject(objRange) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > objRange = Nothing > > objExcelWorksheet = Nothing > > objExcelWorkBook = Nothing > > objExcelApp = Nothing > > End Sub > > "Scott M." wrote: > > Quote: > >> 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" <MSDNNospam248@xxxxxx> wrote in message > >> news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@xxxxxx > >> >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.ReleaseComObject(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.ReleaseComObject(objExcelApp) > >> > > >> > Sub Test2 > >> > Dim objExcelApp As New Excel.Application > >> > > >> > > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > >> > > >> > objExcelApp = Nothing > >> > End Sub > >> > > >> > > >> > What is it that is keeping a reference to the Excel process and how do > >> > I > >> > kill the process? > >> > >> > >> > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Excel does not die using automation What version of .NET are you using? Excel closes in my console app when I try. "Terry Holland" <MSDNNospam248@xxxxxx> wrote in message news:BE108C26-9B16-46B8-B343-B02E2EFDA1FE@xxxxxx Quote: >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.ReleaseComObject(objRange) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > objRange = Nothing > objExcelWorksheet = Nothing > objExcelWorkBook = Nothing > objExcelApp = Nothing > > Console.WriteLine("Waiting") > Console.Read() > End Sub > > End Module > "Scott M." wrote: > Quote: >> 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" <MSDNNospam248@xxxxxx> wrote in message >> news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3@xxxxxx Quote: >> > 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.ReleaseComObject(objRange) >> > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) >> > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) >> > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(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" <MSDNNospam248@xxxxxx> wrote in message >> >> news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@xxxxxx >> >> >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.ReleaseComObject(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.ReleaseComObject(objExcelApp) >> >> > >> >> > Sub Test2 >> >> > Dim objExcelApp As New Excel.Application >> >> > >> >> > >> >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) >> >> > >> >> > objExcelApp = Nothing >> >> > End Sub >> >> > >> >> > >> >> > What is it that is keeping a reference to the Excel process and how >> >> > do >> >> > I >> >> > kill the process? >> >> >> >> >> >> >> >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Excel does not die using automation im using .net 2.0 "Scott M." wrote: Quote: > What version of .NET are you using? Excel closes in my console app when I > try. > > > "Terry Holland" <MSDNNospam248@xxxxxx> wrote in message > news:BE108C26-9B16-46B8-B343-B02E2EFDA1FE@xxxxxx Quote: > >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.ReleaseComObject(objRange) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > objRange = Nothing > > objExcelWorksheet = Nothing > > objExcelWorkBook = Nothing > > objExcelApp = Nothing > > > > Console.WriteLine("Waiting") > > Console.Read() > > End Sub > > > > End Module > > "Scott M." wrote: > > Quote: > >> 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" <MSDNNospam248@xxxxxx> wrote in message > >> news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3@xxxxxx > >> > 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.ReleaseComObject(objRange) > >> > > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > >> > > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > >> > > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(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" <MSDNNospam248@xxxxxx> wrote in message > >> >> news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@xxxxxx > >> >> >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.ReleaseComObject(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.ReleaseComObject(objExcelApp) > >> >> > > >> >> > Sub Test2 > >> >> > Dim objExcelApp As New Excel.Application > >> >> > > >> >> > > >> >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > >> >> > > >> >> > objExcelApp = Nothing > >> >> > End Sub > >> >> > > >> >> > > >> >> > What is it that is keeping a reference to the Excel process and how > >> >> > do > >> >> > I > >> >> > kill the process? > >> >> > >> >> > >> >> > >> > >> > >> > > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Excel does not die using automation On Jul 6, 1:53*pm, Terry Holland <MSDNNospam...@xxxxxx> wrote: Quote: > 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.ReleaseComObject(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.ReleaseComObject(objExcelApp) > > Sub Test2 > * * * * Dim objExcelApp As NewExcel.Application > > * * * * System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > * * * * objExcelApp = Nothing > End Sub > > What is it that is keeping a reference to theExcelprocess and how do I > kill the process? 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 |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Excel does not die using automation It looks to me like you've created a race condition. You need to call objExcelApp.Quit() after you've released all of the COM objects you've been using (except for the excel application instance), not before. Also, as you've done below make sure you release the objects inversely from the order they were instantiated. The last object you created becomes the first object you're releasing. Other than that, your application looks fine to me. "Terry Holland" wrote: Quote: > 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.ReleaseComObject(objRange) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > objRange = Nothing > objExcelWorksheet = Nothing > objExcelWorkBook = Nothing > objExcelApp = Nothing > End Sub > "Scott M." wrote: > Quote: > > 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" <MSDNNospam248@xxxxxx> wrote in message > > news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@xxxxxx Quote: > > >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.ReleaseComObject(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.ReleaseComObject(objExcelApp) > > > > > > Sub Test2 > > > Dim objExcelApp As New Excel.Application > > > > > > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > > > objExcelApp = Nothing > > > End Sub > > > > > > > > > What is it that is keeping a reference to the Excel process and how do I > > > kill the process? > > > > |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Excel does not die using automation "Jeff Winn" <JeffWinn@xxxxxx> wrote in message news:6AEC2118-C87D-4EDA-9560-AE84337F107A@xxxxxx Quote: > It looks to me like you've created a race condition. You need to call > objExcelApp.Quit() after you've released all of the COM objects you've > been > using (except for the excel application instance), not before. explicitly create Excel objects and explictly release them (in the opposite order you created them), you should have no trouble calling ReleaseComObject() After quitting Excel. As I said, I have the code working just fine: Imports System.Runtime.InteropServices 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 = objExcelWorksheet.Range("A1") objExcelApp.Visible = True objExcelWorkBook.Close() objExcelApp.Quit() Marshal.ReleaseComObject(objRange) Marshal.ReleaseComObject(objExcelWorksheet) Marshal.ReleaseComObject(objExcelWorkBook) Marshal.ReleaseComObject(objExcelApp) objRange = Nothing objExcelWorksheet = Nothing objExcelWorkBook = Nothing objExcelApp = Nothing End Sub |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: excel automation | VB Script | |||
| Excel Automation - Determine the Columns Selected | .NET General | |||
| Slow Excel Automation | PowerShell | |||
| Vista ASP.NET 2.0 Cannot open Excel File using Microsoft.Excel 12.0 COM object | Microsoft Office | |||
| Excel automation | PowerShell | |||