title: recognize an onclose event with OleVariant?
body: <p>I´m using a OleAutomation with <strong>Excel := CreateOleObject('Excel.Application');</strong>
  to use the functions <strong>Excel.Replace</strong> and <strong>Excel.SaveAs</strong>. These functions are essential in my problem and I cannot leave them out. On the other hand I have to use an <strong>OleVariant</strong> type, which has <strong>no OnCloseEvent</strong>. Now my problem begins:</p>
  
  <hr>
  
  <p>At first a small overview:</p>
  
  <pre><code>**procedure OpenExcel begins**
  
  Excel := CreateOleObject('Excel.Application'); 
  //Excel opens a template and replaces placeholders 
  
  **procedure OpenExcel end**;
  </code></pre>
  
  <p>Now Excel is open with all placeholders replaced. After this procedure the client can alter his sheet, correct mistakes, .. . Ongoing he wants to close Excel or save the Workbook. </p>
  
  <hr>
  
  <p><strong>And here starts my problem:</strong> I want to <strong>catch the moment</strong>, when the <strong>client closes Excel</strong>. If his document is saved, all data (some strings like path or color and integers like id´s placed in an object) will comitted to another programm named ELO (document archive) before the OleObject will be destroyed. But OleObjects can´t recognize a close or whatever. </p>
  
  <hr>
  
  <h3>Is there a workaround to solve this problem? Perhaps linking an object to the OleObject or the process itself to determine when Excel is closed by the client?</h3>
  
  <p>I looked up if there is a way provided by the \Ocx\Servers\excel200.pas but I didn't found anything. My co-worker advised I should look into the office folder and search for the excel .tlb-file, but it doesn't exsist.</p>
  
  <hr>
  
  <p>IF THE PROBLEM ABOVE CANNOT BE SOLVED</p>
  
  <hr>
  
  <p>If this isn´t possible do anyone know how I can use <strong>Excel.Replace</strong> and <strong>Excel.SaveAs</strong> with an object, which has a OnClose Event?</p>
  
  <p>My current code for <strong>replacement</strong> is the following:</p>
  
  <pre><code>//for all sheets in the workbook
  for iSheet := 1 to Excel.Worksheets.Count do
  begin
  
    //activate the sheet
    Excel.Worksheets[iSheet].Activate;
  
    // this will be..
    sWhat := %First String%;  
    //..replaced by..
    sReplacement := %Second String%;
  
    // warnings off (override message or if excel didn't find a sWhat)
    Excel.Application.DisplayAlerts := False;
  
    Excel.Cells.Replace(
      What          := sWhat,
      Replacement   := sReplacement,
      LookAt        := xlWhole,
      SearchOrder   := xlByRows,
      MatchCase     := False,
      SearchFormat  := False,
      ReplaceFormat := False
    );
  
    //warnings on
    Excel.Application.DisplayAlerts := True;
  end;
  </code></pre>
  
  <p>The <strong>SaveAs method</strong> is similiar. It just sends a command which excel itself can handle like the <strong>Excel.Cells.Replace</strong>.</p>
  
  <p>I hope the description of my problem is clear enough, my english isn't as good as I want it to be..</p>
  
  <p>Thanks in advance!</p>