title: reasons why excel.exe remains loaded after running a delphi client automation program?
body: <p>I wrote a Delphi program that extracts and consolidates data from several different spreadsheets of a single .XLS file, to a text file for later processing. It is a Delphi 7 <strong>console</strong> program.</p>
  
  <p>An excerpt of the most relevant pieces of code will show you that, apparently, my program is pretty well behaved or at least as much as it needs to be.</p>
  
  <pre><code>uses ...  ActiveX, ComObj ... ;
  
  procedure Fatal(s:string);
    ...
    Halt(1);
  
  var ExcelApp:Variant; (* global var *)
  
  begin (* main program block *)
    coInitialize(nil);
    ExcelApp:=CreateOleObject('Excel.Application');
    try
      ExcelApp.Visible:=False;
      ExcelApp.WorkBooks.Open(ExcelFileName);
    ...
      XLSSheet := ExcelApp.Worksheets[ExcelSheetName];
    ...
      try
        XLSRange := XLSSheet.Range[ExcelRangeName];
      except
        Fatal('Range "'+ExcelRangeName+'" not found');
      end;
      if VarIsNull(XLSRange) then Fatal('Range '+ExcelRangeName+' not found');
      for row:=XLSRange.Row to XLSRange.Rows[XLSRange.Rows.Count].Row do
        for col:=XLSRange.Column to XLSRange.Columns[XLSRange.Columns.Count].Column do
          CellValue:=XLSSheet.Cells[Row,Col].Value;
          ...
          if CellValue&lt;&gt;'' then ...
          ...
      ExcelApp.Workbooks.Close;
      ...
    finally
      ExcelApp.Quit;
      coUninitialize;
    end;   
  end.
  </code></pre>
  
  <p>Sometimes, when the program exits, the XLS remains locked. Looking at the Task Manager, I see that Excel.exe process that was started when the client program ran, is still running, eventhoug the client program has exited and succesfully unloaded.</p>
  
  <p>Do you happen to know what are the usual suspects for this behaviour? have any idea where to look for always unloading excel upon client execution?</p>