Excel Issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murali369
    New Member
    • Sep 2008
    • 1

    Excel Issues

    I have a referrence to Excel 12.0 Object Library in my application. I have made the visible set to false for Excel and doing all my work. When iam trying to terminate the excel while application termination it is closing all the other opened excel workbooks.

    Please give a solution.
    The code is somewhat like this:

    Try
    Dim pProcess As Process
    exlHandle = oexcel.Hwnd
    GetWindowThread ProcessId(exlHa ndle, exlProcessId)
    pProcess = System.Diagnost ics.Process.Get ProcessById(exl ProcessId)
    pProcess.Kill()
    Catch ex As Exception
    Return
    End Try



    Thanks in Advance
    Murali Krishna
  • dnnddane
    New Member
    • Sep 2008
    • 7

    #2
    Excel 12.0 object library is a com component, so you can't exit it by using
    objExcelApplica tion.Quit();
    As a reason, you will still see Excel.exe in task manager.

    I guess you are trying to teminate the excel process, but it's not a good solution because you will teminate all excel application.

    try this:
    ....
    ....
    //Quit excel app
    objExcelApplica tion.Quit();
    //Release com object
    System.Runtime. InteropServices .Marshal.Releas eComObject(objE xcelApplication );
    System.Runtime. InteropServices .Marshal.Releas eComObject(objW orkBook);
    System.Runtime. InteropServices .Marshal.Releas eComObject(objW orkSheet);
    objExcelApplica tion = null;
    objWorkBook = null;
    objWorkSheet = null;
    GC.Collect();

    The above code is to release com object from memory.

    Give me five if this can help you.

    Dane(from Cambodia)

    Comment

    • amwggyy504
      New Member
      • Sep 2008
      • 5

      #3
      The excel process must be close,like this:

      ------------------------------------------
      finally
      {
      wb.Close(Type.M issing, Type.Missing, Type.Missing);
      oExcel.Quit();
      System.Runtime. InteropServices .Marshal.Releas eComObject(oExc el);
      oExcel = null;
      GC.Collect();
      System.Diagnost ics.Process[] ps = System.Diagnost ics.Process.Get Processes();
      for (int i = 0; i < ps.Length; i++)
      {
      if (ps[i].ProcessName.To Upper() == "EXCEL")
      {
      ps[i].Kill();
      }
      }
      }
      ----------------------------------
      but all excel process will be close.

      referrence http://www.cnblogs.com/amwggyy504/ar...6/1251976.html

      Comment

      Working...