Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to kill an Excel process?

How to kill an Excel process?

Scheduled Pinned Locked Moved Visual Basic
helpcsscomperformancetutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Juan Pedro Prez
    wrote on last edited by
    #1

    Hello, I'm making a program that make use of Excel. In it, I create an Excel application and then make it visible, then perform several operations with it. Up to this point, everything OK. The problem comes when I try to close the Excel. At first I thougt that, being an object created within my app, the process will be destroyed by the garbage collector. Then I realized that not. I tried to use the ExcelApp.Quit() method, but it doesn't work either. In conclusion, I find myself with my program closed, but with a residual Excel process within an SVCHOST parent process I can't kill. Things turn to worse when I execute my app several times: I end up with several Excel processes, consuming no less than 8MB of memory each!!! I invoke the Excel with the following code: Imports Microsoft.Office.Interop.Excel ... Private Excel As New Microsoft.Office.Interop.Excel.Application() ' el Excel What can I do? Any help will be welcomed! Thanks in advance, Juan Pedro Pérez

    D 1 Reply Last reply
    0
    • J Juan Pedro Prez

      Hello, I'm making a program that make use of Excel. In it, I create an Excel application and then make it visible, then perform several operations with it. Up to this point, everything OK. The problem comes when I try to close the Excel. At first I thougt that, being an object created within my app, the process will be destroyed by the garbage collector. Then I realized that not. I tried to use the ExcelApp.Quit() method, but it doesn't work either. In conclusion, I find myself with my program closed, but with a residual Excel process within an SVCHOST parent process I can't kill. Things turn to worse when I execute my app several times: I end up with several Excel processes, consuming no less than 8MB of memory each!!! I invoke the Excel with the following code: Imports Microsoft.Office.Interop.Excel ... Private Excel As New Microsoft.Office.Interop.Excel.Application() ' el Excel What can I do? Any help will be welcomed! Thanks in advance, Juan Pedro Pérez

      D Offline
      D Offline
      Dean_SF
      wrote on last edited by
      #2

      Give this a try when you are done using Excel: ' Release Application object: If Not oExcel.UserControl Then oExcel.UserControl = True System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel) 'Release worksheet: If Not oWorkSheet Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(oWorkSheet) oWorkSheet = Nothing End If 'Release workbook: If Not oWorkBook Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(oWorkBook) oWorkBook = Nothing End If oExcel = Nothing oExcel is your Excel application object. oWorksheet is your Excel worksheet object if you have one instantiated. oWorkbook is your Excel workbook object if you have one instantiated. Dean

      J 1 Reply Last reply
      0
      • D Dean_SF

        Give this a try when you are done using Excel: ' Release Application object: If Not oExcel.UserControl Then oExcel.UserControl = True System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel) 'Release worksheet: If Not oWorkSheet Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(oWorkSheet) oWorkSheet = Nothing End If 'Release workbook: If Not oWorkBook Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(oWorkBook) oWorkBook = Nothing End If oExcel = Nothing oExcel is your Excel application object. oWorksheet is your Excel worksheet object if you have one instantiated. oWorkbook is your Excel workbook object if you have one instantiated. Dean

        J Offline
        J Offline
        Juan Pedro Prez
        wrote on last edited by
        #3

        Thanks Dean, I'll try this and I'll tell you how it works. Juan Pedro Pérez

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups