Excel does not die using automation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=

    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.Applicati on

    Dim objExcelWorkBoo k As Excel.Workbook =
    objExcelApp.Wor kbooks.Open("C: \Test.xls")
    Dim objExcelWorkshe et As Excel.Worksheet = objExcelWorkBoo k.Sheets(1)

    Dim objRange As Excel.Range
    objRange = objExcelWorkshe et.Range("A1")
    MsgBox(objRange .Text)
    ''http://www.vbforums.co m/archive/index.php/t-396405.html
    objRange = Nothing
    objExcelWorkshe et = Nothing
    objExcelWorkBoo k.Close()
    objExcelWorkBoo k = Nothing
    objExcelApp.Wor kbooks.Close()
    objExcelApp.Qui t()

    System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

    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.Applicati on
    and killed on line
    System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

    Sub Test2
    Dim objExcelApp As New Excel.Applicati on

    System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

    objExcelApp = Nothing
    End Sub


    What is it that is keeping a reference to the Excel process and how do I
    kill the process?
  • Scott M.

    #2
    Re: Excel does not die using automation

    You must call ReleaseComObjec t(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.Applicati on.

    "Terry Holland" <MSDNNospam248@ nospam.nospamwr ote in message
    news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@mi crosoft.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.Applicati on
    >
    Dim objExcelWorkBoo k As Excel.Workbook =
    objExcelApp.Wor kbooks.Open("C: \Test.xls")
    Dim objExcelWorkshe et As Excel.Worksheet =
    objExcelWorkBoo k.Sheets(1)
    >
    Dim objRange As Excel.Range
    objRange = objExcelWorkshe et.Range("A1")
    MsgBox(objRange .Text)
    ''http://www.vbforums.co m/archive/index.php/t-396405.html
    objRange = Nothing
    objExcelWorkshe et = Nothing
    objExcelWorkBoo k.Close()
    objExcelWorkBoo k = Nothing
    objExcelApp.Wor kbooks.Close()
    objExcelApp.Qui t()
    >
    >
    System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
    >
    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.Applicati on
    and killed on line
    >
    System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
    >
    Sub Test2
    Dim objExcelApp As New Excel.Applicati on
    >
    >
    System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
    >
    objExcelApp = Nothing
    End Sub
    >
    >
    What is it that is keeping a reference to the Excel process and how do I
    kill the process?

    Comment

    • =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=

      #3
      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.Applicati on
      Dim objExcelWorkBoo k As Excel.Workbook =
      objExcelApp.Wor kbooks.Open("C: \Test.xls")
      Dim objExcelWorkshe et As Excel.Worksheet = objExcelWorkBoo k.Sheets(1)
      Dim objRange As Excel.Range

      objRange = objExcelWorkshe et.Range("A1")
      MsgBox(objRange .Text)

      objExcelWorkBoo k.Close()
      objExcelApp.Qui t()

      System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)

      System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)

      System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)
      System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

      objRange = Nothing
      objExcelWorkshe et = Nothing
      objExcelWorkBoo k = Nothing
      objExcelApp = Nothing
      End Sub
      "Scott M." wrote:
      You must call ReleaseComObjec t(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.Applicati on.
      >
      "Terry Holland" <MSDNNospam248@ nospam.nospamwr ote in message
      news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@mi crosoft.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.Applicati on

      Dim objExcelWorkBoo k As Excel.Workbook =
      objExcelApp.Wor kbooks.Open("C: \Test.xls")
      Dim objExcelWorkshe et As Excel.Worksheet =
      objExcelWorkBoo k.Sheets(1)

      Dim objRange As Excel.Range
      objRange = objExcelWorkshe et.Range("A1")
      MsgBox(objRange .Text)
      ''http://www.vbforums.co m/archive/index.php/t-396405.html
      objRange = Nothing
      objExcelWorkshe et = Nothing
      objExcelWorkBoo k.Close()
      objExcelWorkBoo k = Nothing
      objExcelApp.Wor kbooks.Close()
      objExcelApp.Qui t()


      System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

      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.Applicati on
      and killed on line

      System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

      Sub Test2
      Dim objExcelApp As New Excel.Applicati on


      System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

      objExcelApp = Nothing
      End Sub


      What is it that is keeping a reference to the Excel process and how do I
      kill the process?
      >
      >
      >

      Comment

      • Scott M.

        #4
        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@ nospam.nospamwr ote in message
        news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3@mi crosoft.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.Applicati on
        Dim objExcelWorkBoo k As Excel.Workbook =
        objExcelApp.Wor kbooks.Open("C: \Test.xls")
        Dim objExcelWorkshe et As Excel.Worksheet =
        objExcelWorkBoo k.Sheets(1)
        Dim objRange As Excel.Range
        >
        objRange = objExcelWorkshe et.Range("A1")
        MsgBox(objRange .Text)
        >
        objExcelWorkBoo k.Close()
        objExcelApp.Qui t()
        >
        System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)
        >
        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)
        >
        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)
        >
        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
        >
        objRange = Nothing
        objExcelWorkshe et = Nothing
        objExcelWorkBoo k = Nothing
        objExcelApp = Nothing
        End Sub
        "Scott M." wrote:
        >
        >You must call ReleaseComObjec t(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.Applicati on.
        >>
        >"Terry Holland" <MSDNNospam248@ nospam.nospamwr ote in message
        >news:9B590AD 1-E4A3-4EA8-84AA-8A0358F3673A@mi crosoft.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.Applicati on
        >
        Dim objExcelWorkBoo k As Excel.Workbook =
        objExcelApp.Wor kbooks.Open("C: \Test.xls")
        Dim objExcelWorkshe et As Excel.Worksheet =
        objExcelWorkBoo k.Sheets(1)
        >
        Dim objRange As Excel.Range
        objRange = objExcelWorkshe et.Range("A1")
        MsgBox(objRange .Text)
        ''http://www.vbforums.co m/archive/index.php/t-396405.html
        objRange = Nothing
        objExcelWorkshe et = Nothing
        objExcelWorkBoo k.Close()
        objExcelWorkBoo k = Nothing
        objExcelApp.Wor kbooks.Close()
        objExcelApp.Qui t()
        >
        >
        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
        >
        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.Applicati on
        and killed on line
        >
        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
        >
        Sub Test2
        Dim objExcelApp As New Excel.Applicati on
        >
        >
        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
        >
        objExcelApp = Nothing
        End Sub
        >
        >
        What is it that is keeping a reference to the Excel process and how do
        I
        kill the process?
        >>
        >>
        >>

        Comment

        • =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=

          #5
          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.Offic e.Interop

          Module Module1

          Sub Main()
          Dim objExcelApp As New Excel.Applicati on
          Dim objExcelWorkBoo k As Excel.Workbook =
          objExcelApp.Wor kbooks.Open("C: \Test.xls")
          Dim objExcelWorkshe et As Excel.Worksheet = objExcelWorkBoo k.Sheets(1)
          Dim objRange As Excel.Range

          objRange = objExcelWorkshe et.Range("A1")
          Console.WriteLi ne(objRange.Tex t)
          'Console.Read()


          objExcelWorkBoo k.Close()
          objExcelApp.Qui t()

          System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)

          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)

          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)
          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

          objRange = Nothing
          objExcelWorkshe et = Nothing
          objExcelWorkBoo k = Nothing
          objExcelApp = Nothing

          Console.WriteLi ne("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" <MSDNNospam248@ nospam.nospamwr ote in message
          news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3@mi crosoft.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.Applicati on
          Dim objExcelWorkBoo k As Excel.Workbook =
          objExcelApp.Wor kbooks.Open("C: \Test.xls")
          Dim objExcelWorkshe et As Excel.Worksheet =
          objExcelWorkBoo k.Sheets(1)
          Dim objRange As Excel.Range

          objRange = objExcelWorkshe et.Range("A1")
          MsgBox(objRange .Text)

          objExcelWorkBoo k.Close()
          objExcelApp.Qui t()

          System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)

          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)

          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)

          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

          objRange = Nothing
          objExcelWorkshe et = Nothing
          objExcelWorkBoo k = Nothing
          objExcelApp = Nothing
          End Sub
          "Scott M." wrote:
          You must call ReleaseComObjec t(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.Applicati on.
          >
          "Terry Holland" <MSDNNospam248@ nospam.nospamwr ote in message
          news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@mi crosoft.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.Applicati on

          Dim objExcelWorkBoo k As Excel.Workbook =
          objExcelApp.Wor kbooks.Open("C: \Test.xls")
          Dim objExcelWorkshe et As Excel.Worksheet =
          objExcelWorkBoo k.Sheets(1)

          Dim objRange As Excel.Range
          objRange = objExcelWorkshe et.Range("A1")
          MsgBox(objRange .Text)
          ''http://www.vbforums.co m/archive/index.php/t-396405.html
          objRange = Nothing
          objExcelWorkshe et = Nothing
          objExcelWorkBoo k.Close()
          objExcelWorkBoo k = Nothing
          objExcelApp.Wor kbooks.Close()
          objExcelApp.Qui t()


          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

          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.Applicati on
          and killed on line

          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

          Sub Test2
          Dim objExcelApp As New Excel.Applicati on


          System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

          objExcelApp = Nothing
          End Sub


          What is it that is keeping a reference to the Excel process and how do
          I
          kill the process?
          >
          >
          >
          >
          >
          >

          Comment

          • Scott M.

            #6
            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@ nospam.nospamwr ote in message
            news:BE108C26-9B16-46B8-B343-B02E2EFDA1FE@mi crosoft.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.Offic e.Interop
            >
            Module Module1
            >
            Sub Main()
            Dim objExcelApp As New Excel.Applicati on
            Dim objExcelWorkBoo k As Excel.Workbook =
            objExcelApp.Wor kbooks.Open("C: \Test.xls")
            Dim objExcelWorkshe et As Excel.Worksheet =
            objExcelWorkBoo k.Sheets(1)
            Dim objRange As Excel.Range
            >
            objRange = objExcelWorkshe et.Range("A1")
            Console.WriteLi ne(objRange.Tex t)
            'Console.Read()
            >
            >
            objExcelWorkBoo k.Close()
            objExcelApp.Qui t()
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
            >
            objRange = Nothing
            objExcelWorkshe et = Nothing
            objExcelWorkBoo k = Nothing
            objExcelApp = Nothing
            >
            Console.WriteLi ne("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
            >representati on 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@ nospam.nospamwr ote in message
            >news:29BA0CA 5-F757-4233-B1ED-7DE4D13AC7B3@mi crosoft.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.Applicati on
            Dim objExcelWorkBoo k As Excel.Workbook =
            objExcelApp.Wor kbooks.Open("C: \Test.xls")
            Dim objExcelWorkshe et As Excel.Worksheet =
            objExcelWorkBoo k.Sheets(1)
            Dim objRange As Excel.Range
            >
            objRange = objExcelWorkshe et.Range("A1")
            MsgBox(objRange .Text)
            >
            objExcelWorkBoo k.Close()
            objExcelApp.Qui t()
            >
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
            >
            objRange = Nothing
            objExcelWorkshe et = Nothing
            objExcelWorkBoo k = Nothing
            objExcelApp = Nothing
            End Sub
            "Scott M." wrote:
            >
            >You must call ReleaseComObjec t(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.Applicati on.
            >>
            >"Terry Holland" <MSDNNospam248@ nospam.nospamwr ote in message
            >news:9B590AD 1-E4A3-4EA8-84AA-8A0358F3673A@mi crosoft.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.Applicati on
            >
            Dim objExcelWorkBoo k As Excel.Workbook =
            objExcelApp.Wor kbooks.Open("C: \Test.xls")
            Dim objExcelWorkshe et As Excel.Worksheet =
            objExcelWorkBoo k.Sheets(1)
            >
            Dim objRange As Excel.Range
            objRange = objExcelWorkshe et.Range("A1")
            MsgBox(objRange .Text)
            ''http://www.vbforums.co m/archive/index.php/t-396405.html
            objRange = Nothing
            objExcelWorkshe et = Nothing
            objExcelWorkBoo k.Close()
            objExcelWorkBoo k = Nothing
            objExcelApp.Wor kbooks.Close()
            objExcelApp.Qui t()
            >
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
            >
            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.Applicati on
            and killed on line
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
            >
            Sub Test2
            Dim objExcelApp As New Excel.Applicati on
            >
            >
            System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
            >
            objExcelApp = Nothing
            End Sub
            >
            >
            What is it that is keeping a reference to the Excel process and how
            do
            I
            kill the process?
            >>
            >>
            >>
            >>
            >>
            >>

            Comment

            • =?Utf-8?B?VGVycnkgSG9sbGFuZA==?=

              #7
              Re: Excel does not die using automation

              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" <MSDNNospam248@ nospam.nospamwr ote in message
              news:BE108C26-9B16-46B8-B343-B02E2EFDA1FE@mi crosoft.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.Offic e.Interop

              Module Module1

              Sub Main()
              Dim objExcelApp As New Excel.Applicati on
              Dim objExcelWorkBoo k As Excel.Workbook =
              objExcelApp.Wor kbooks.Open("C: \Test.xls")
              Dim objExcelWorkshe et As Excel.Worksheet =
              objExcelWorkBoo k.Sheets(1)
              Dim objRange As Excel.Range

              objRange = objExcelWorkshe et.Range("A1")
              Console.WriteLi ne(objRange.Tex t)
              'Console.Read()


              objExcelWorkBoo k.Close()
              objExcelApp.Qui t()

              System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)

              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)

              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)

              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

              objRange = Nothing
              objExcelWorkshe et = Nothing
              objExcelWorkBoo k = Nothing
              objExcelApp = Nothing

              Console.WriteLi ne("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" <MSDNNospam248@ nospam.nospamwr ote in message
              news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3@mi crosoft.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.Applicati on
              Dim objExcelWorkBoo k As Excel.Workbook =
              objExcelApp.Wor kbooks.Open("C: \Test.xls")
              Dim objExcelWorkshe et As Excel.Worksheet =
              objExcelWorkBoo k.Sheets(1)
              Dim objRange As Excel.Range

              objRange = objExcelWorkshe et.Range("A1")
              MsgBox(objRange .Text)

              objExcelWorkBoo k.Close()
              objExcelApp.Qui t()


              System.Runtime. InteropServices .Marshal.Releas eComObject(objR ange)

              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorksheet)

              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelWorkBook)

              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

              objRange = Nothing
              objExcelWorkshe et = Nothing
              objExcelWorkBoo k = Nothing
              objExcelApp = Nothing
              End Sub
              "Scott M." wrote:

              You must call ReleaseComObjec t(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.Applicati on.
              >
              "Terry Holland" <MSDNNospam248@ nospam.nospamwr ote in message
              news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A@mi crosoft.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.Applicati on

              Dim objExcelWorkBoo k As Excel.Workbook =
              objExcelApp.Wor kbooks.Open("C: \Test.xls")
              Dim objExcelWorkshe et As Excel.Worksheet =
              objExcelWorkBoo k.Sheets(1)

              Dim objRange As Excel.Range
              objRange = objExcelWorkshe et.Range("A1")
              MsgBox(objRange .Text)
              ''http://www.vbforums.co m/archive/index.php/t-396405.html
              objRange = Nothing
              objExcelWorkshe et = Nothing
              objExcelWorkBoo k.Close()
              objExcelWorkBoo k = Nothing
              objExcelApp.Wor kbooks.Close()
              objExcelApp.Qui t()


              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

              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.Applicati on
              and killed on line

              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

              Sub Test2
              Dim objExcelApp As New Excel.Applicati on


              System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)

              objExcelApp = Nothing
              End Sub


              What is it that is keeping a reference to the Excel process and how
              do
              I
              kill the process?
              >
              >
              >
              >
              >
              >
              >
              >
              >

              Comment

              • ZSvedic

                #8
                Re: Excel does not die using automation

                On Jul 6, 1:53 pm, Terry Holland <MSDNNospam...@ nospam.nospamwr ote:
                I have a vb.net app that opens anexcelworkshee t, 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.Applic ation
                >
                        Dim objExcelWorkBoo k AsExcel.Workboo k =
                objExcelApp.Wor kbooks.Open("C: \Test.xls")
                        Dim objExcelWorkshe et AsExcel.Workshe et = objExcelWorkBoo k.Sheets(1)
                >
                        Dim objRange AsExcel.Range
                        objRange = objExcelWorkshe et.Range("A1")
                        MsgBox(objRange .Text)
                        ''http://www.vbforums.co m/archive/index.php/t-396405.html
                        objRange = Nothing
                        objExcelWorkshe et = Nothing
                        objExcelWorkBoo k.Close()
                        objExcelWorkBoo k = Nothing
                        objExcelApp.Wor kbooks.Close()
                        objExcelApp.Qui t()
                >
                        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
                >
                        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.Applic ation
                and killed on line
                        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
                >
                Sub Test2
                        Dim objExcelApp As NewExcel.Applic ation
                >
                        System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApp)
                >
                        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.Spreadsh eet Free (http://www.gemboxsoftware.com/
                GBSpreadsheetFr ee.htm)
                Excel component for XLS/CSV/XLSX reading/writing/reporting.
                Automation has many issues: http://www.gemboxsoftware.com/GBSpre...htm#Automation

                --Zeljko

                Comment

                Working...