Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EOleSysError-exception with GetActiveOleObject(...)

309 views
Skip to first unread message

Joachim Wörner

unread,
May 10, 2001, 7:01:05 PM5/10/01
to
Hi!

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


Binh Ly

unread,
May 10, 2001, 11:44:04 PM5/10/01
to
"Joachim Wörner" <j...@woerner-edv-systeme.de> wrote in message
news:3afb1d0d$1_1@dnews...

> Hi!
>
> 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.

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


Joachim Wörner

unread,
May 11, 2001, 4:16:24 AM5/11/01
to

> > try
> > Excel:= GetActiveOleObject('Excel.Application');
> > except
> > Excel:= CreateOleObject('Excel.Application');
> > end;
> >
> 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.

How can I this be switched off? I don't want the program to stop.

Thanx !!

Jo


Deborah Pate (TeamB)

unread,
May 11, 2001, 5:24:24 AM5/11/01
to
<<Joachim Wörner:

How can I this be switched off? I don't want the program to
stop.
>>

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


Joachim Wörner

unread,
May 20, 2001, 3:56:17 PM5/20/01
to
Hi Deborah Pate!

Thank you!!

You helped me very much with your answer!
Now it work's fine.

Joachim


0 new messages