I´m using a OleAutomation with Excel := CreateOleObject('Excel.Application'); to use the functions Excel.Replace and Excel.SaveAs. These functions are essential in my problem and I cannot leave them out. On the other hand I have to use an OleVariant type, which has no OnCloseEvent. Now my problem begins:
At first a small overview:
**procedure OpenExcel begins**
Excel := CreateOleObject('Excel.Application');
//Excel opens a template and replaces placeholders
**procedure OpenExcel end**;
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.
And here starts my problem: I want to catch the moment, when the client closes Excel. 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.
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?
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.
IF THE PROBLEM ABOVE CANNOT BE SOLVED
If this isn´t possible do anyone know how I can use Excel.Replace and Excel.SaveAs with an object, which has a OnClose Event?
My current code for replacement is the following:
//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;
The SaveAs method is similiar. It just sends a command which excel itself can handle like the Excel.Cells.Replace.
I hope the description of my problem is clear enough, my english isn't as good as I want it to be..
Thanks in advance!