I get an EOleSysError-exception when i call GetActiveOleObject, this ist the
relevant source code:
try
Excel:= GetActiveOleObject('Excel.Application');
except
Excel:= CreateOleObject('Excel.Application');
end;
It works fine, when Excel is running, but when Excel ist not openend, the
program stops running with this exception.
>>> What can I do to prevent my program from stopping with this exception?
<<<
(I use late binding)
The main thing what I want, is to determine, if an Excel-Sheet, which I want
to read, is already opened.
If it is openend, I want to read this opened sheet, in the other case I want
to open it.
I already read in http://www.djpate.freeserve.co.uk, but I still can't solve
this problem.
Thank you for any hint !!!!!
Bye, Joachim
This should work fine. If you're in debug mode in the IDE, an exception will
be caught by the IDE but then if you continue running, The code in your
except block should execute and then everything after that.
--
have fun
Binh Ly
www.techvanguards.com
How can I this be switched off? I don't want the program to stop.
Thanx !!
Jo
You can set the Tools | Debugger options | Language
Exceptions | Stop on Delphi exceptions option to False, or
you can Add (in the same dialog) EOleSysError to the list
of exception types to ignore (D5).
Alternatively you can use code that doesn't trigger an
exception if Excel is not running:
function GetExcel: IDispatch;
var
ClassID: TGUID;
Unknown: IUnknown;
HR: HResult;
begin
ClassID := ProgIDToClassID('Excel.Application');
HR := GetActiveObject(ClassID, nil, Unknown);
if (HR = MK_E_UNAVAILABLE) then
Result := CreateComObject(ClassID) as IDispatch
else begin
OleCheck(HR);
OleCheck(Unknown.QueryInterface(IDispatch, Result));
end;
end;
--
Deborah Pate (TeamB) http://delphi-jedi.org
Use Borland servers; TeamB don't see posts via ISPs
http://www.borland.com/newsgroups/genl_faqs.html
Thank you!!
You helped me very much with your answer!
Now it work's fine.
Joachim