 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Glenn De Tollenaere Guest
|
Posted: Wed Nov 12, 2003 2:25 pm Post subject: Word automation |
|
|
Hi all,
I have written my own component to communicate with Word. I use the
Word_TLB.pas (import type library) to do so.
Now I would like to achieve the following, if Word is already activated I'd
like to attach to that process instead of creating a new Wordsession.
In Word_TLB the following lines create a new session (or Word OLE-object to
perform actions):
CoApplication_ = class
class function Create: _Application;
class function CreateRemote(const MachineName: string): _Application;
end;
class function CoApplication_.Create: _Application;
begin
Result := CreateComObject(CLASS_Application_) as _Application;
end;
Does anyone have any idea how to attach to an already active Wordsession by
using this Word_TLB-type library ?
Any help appreciated
Glenn De Tollenaere
|
|
| Back to top |
|
 |
Richard Teller Guest
|
Posted: Wed Nov 12, 2003 2:38 pm Post subject: Re: Word automation |
|
|
Glenn
I use this (which I got from Deborah Pates excellent "get started" COM
site)
var
MSWord: WordApplication;
....
AppWasRunning := False;
Res := GetActiveObject(CLASS_WordApplication, nil, Unknown);
if (Res = MK_E_UNAVAILABLE) then
MSWord := CoWordApplication.Create
else begin
OleCheck(Res);
OleCheck(Unknown.QueryInterface(_Application, MSWord));
AppWasRunning := True;
end;
then at the end you can do
if not AppWasRunning then begin
MSWord.Quit;
MSWord := nil;
end;
Hoe this helps
Richard Teller
"Glenn De Tollenaere" <gdt (AT) nospam (DOT) com> wrote
| Quote: | Hi all,
I have written my own component to communicate with Word. I use the
Word_TLB.pas (import type library) to do so.
Now I would like to achieve the following, if Word is already activated
I'd
like to attach to that process instead of creating a new Wordsession.
In Word_TLB the following lines create a new session (or Word OLE-object
to
perform actions):
CoApplication_ = class
class function Create: _Application;
class function CreateRemote(const MachineName: string): _Application;
end;
class function CoApplication_.Create: _Application;
begin
Result := CreateComObject(CLASS_Application_) as _Application;
end;
Does anyone have any idea how to attach to an already active Wordsession
by
using this Word_TLB-type library ?
Any help appreciated
Glenn De Tollenaere
|
|
|
| Back to top |
|
 |
Kim Doran Guest
|
Posted: Thu Nov 13, 2003 3:27 pm Post subject: Re: Word automation |
|
|
Do you need to explicitly import anything to get this to work as I am having
a similar problem but with Excel. I get an access violation when it comes to
the QueryInterface call. Also the condition
Res = MK_E_UNAVAILABLE never seems to be satisfied even if Excel is not
running.
-Kim
"Richard Teller" <rteller (AT) doctors (DOT) org.uk> wrote
| Quote: | Glenn
I use this (which I got from Deborah Pates excellent "get started" COM
site)
var
MSWord: WordApplication;
...
AppWasRunning := False;
Res := GetActiveObject(CLASS_WordApplication, nil, Unknown);
if (Res = MK_E_UNAVAILABLE) then
MSWord := CoWordApplication.Create
else begin
OleCheck(Res);
OleCheck(Unknown.QueryInterface(_Application, MSWord));
AppWasRunning := True;
end;
then at the end you can do
if not AppWasRunning then begin
MSWord.Quit;
MSWord := nil;
end;
Hoe this helps
Richard Teller
"Glenn De Tollenaere" <gdt (AT) nospam (DOT) com> wrote in message
news:3fb242d8 (AT) newsgroups (DOT) borland.com...
Hi all,
I have written my own component to communicate with Word. I use the
Word_TLB.pas (import type library) to do so.
Now I would like to achieve the following, if Word is already activated
I'd
like to attach to that process instead of creating a new Wordsession.
In Word_TLB the following lines create a new session (or Word OLE-object
to
perform actions):
CoApplication_ = class
class function Create: _Application;
class function CreateRemote(const MachineName: string):
_Application;
end;
class function CoApplication_.Create: _Application;
begin
Result := CreateComObject(CLASS_Application_) as _Application;
end;
Does anyone have any idea how to attach to an already active Wordsession
by
using this Word_TLB-type library ?
Any help appreciated
Glenn De Tollenaere
|
|
|
| Back to top |
|
 |
Richard Teller Guest
|
Posted: Thu Nov 13, 2003 8:40 pm Post subject: Re: Word automation |
|
|
I have this for (Win2K/Office2K/D5) PowerPoint working fine at the moment
....
uses
Apart from the normal stuff you need....
ComObj, ActiveX, PowerPoint2000_TLB
....
type
TEPowerPoint = class // This is my wrapper
private
PowerPoint: _Application; // This could (and probably should) be
PowerPointApplication;
....
constructor TEPowerPoint.Create;
var
Unknown: IUnknown;
Res: HResult;
begin
inherited Create;
AppWasRunning := False;
Res := GetActiveObject(CLASS_PowerPointApplication, nil, Unknown);
if (Res = MK_E_UNAVAILABLE) then
PowerPoint := CoPowerPointApplication.Create
else begin
OleCheck(Res);
OleCheck(Unknown.QueryInterface(_Application, PowerPoint));
AppWasRunning := True;
end;
Hope this helps
Richard Teller
"Kim Doran" <kim.doran (AT) eircom (DOT) net> wrote
| Quote: | Do you need to explicitly import anything to get this to work as I am
having
a similar problem but with Excel. I get an access violation when it comes
to
the QueryInterface call. Also the condition
Res = MK_E_UNAVAILABLE never seems to be satisfied even if Excel is not
running.
-Kim
"Richard Teller" <rteller (AT) doctors (DOT) org.uk> wrote in message
news:3fb2450e$1 (AT) newsgroups (DOT) borland.com...
Glenn
I use this (which I got from Deborah Pates excellent "get started" COM
site)
var
MSWord: WordApplication;
...
AppWasRunning := False;
Res := GetActiveObject(CLASS_WordApplication, nil, Unknown);
if (Res = MK_E_UNAVAILABLE) then
MSWord := CoWordApplication.Create
else begin
OleCheck(Res);
OleCheck(Unknown.QueryInterface(_Application, MSWord));
AppWasRunning := True;
end;
then at the end you can do
if not AppWasRunning then begin
MSWord.Quit;
MSWord := nil;
end;
Hoe this helps
Richard Teller
"Glenn De Tollenaere" <gdt (AT) nospam (DOT) com> wrote in message
news:3fb242d8 (AT) newsgroups (DOT) borland.com...
Hi all,
I have written my own component to communicate with Word. I use the
Word_TLB.pas (import type library) to do so.
Now I would like to achieve the following, if Word is already
activated
I'd
like to attach to that process instead of creating a new Wordsession.
In Word_TLB the following lines create a new session (or Word
OLE-object
to
perform actions):
CoApplication_ = class
class function Create: _Application;
class function CreateRemote(const MachineName: string):
_Application;
end;
class function CoApplication_.Create: _Application;
begin
Result := CreateComObject(CLASS_Application_) as _Application;
end;
Does anyone have any idea how to attach to an already active
Wordsession
by
using this Word_TLB-type library ?
Any help appreciated
Glenn De Tollenaere
|
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Fri Nov 14, 2003 12:41 am Post subject: Re: Word automation |
|
|
<
Do you need to explicitly import anything to get this to
work
Here's the full Excel version, D5+. Hope it helps.
uses Windows, ComObj, ActiveX, Excel_TLB;
var
Excel: _Application;
AppWasRunning: boolean;
lcid: integer;
Unknown: IUnknown;
Result: HResult;
begin
lcid := LOCALE_USER_DEFAULT;
AppWasRunning := False;
Result :=
GetActiveObject(CLASS_ExcelApplication, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Excel := CoExcelApplication.Create
else begin
OleCheck(Result);
OleCheck(Unknown.QueryInterface(_Application, Excel));
AppWasRunning := True;
end;
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
| Back to top |
|
 |
Glenn De Tollenaere Guest
|
Posted: Fri Nov 14, 2003 2:43 pm Post subject: Re: Word automation |
|
|
Hi,
getactiveobject does not exist (D6 ?). I can use getactiveOleObject, but
that returns IDispatch instead of HResult.
Any idea ?
Regards
Glenn De Tollenaere
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.00001db0.020ae4f6 (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Kim Doran:
Do you need to explicitly import anything to get this to
work
Here's the full Excel version, D5+. Hope it helps.
uses Windows, ComObj, ActiveX, Excel_TLB;
var
Excel: _Application;
AppWasRunning: boolean;
lcid: integer;
Unknown: IUnknown;
Result: HResult;
begin
lcid := LOCALE_USER_DEFAULT;
AppWasRunning := False;
Result :=
GetActiveObject(CLASS_ExcelApplication, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Excel := CoExcelApplication.Create
else begin
OleCheck(Result);
OleCheck(Unknown.QueryInterface(_Application, Excel));
AppWasRunning := True;
end;
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
|
| Back to top |
|
 |
Glenn De Tollenaere Guest
|
Posted: Mon Nov 17, 2003 8:42 am Post subject: Re: Word automation |
|
|
Deborah,
indeed, you're right.
But how can I achieve that the _application-variable, in the case of your
example: Excel, becomes the already opened session (Word in my case) ?
my code (which is part of a self-written component WordAppl):
private
{ Private declarations }
fapplication :_application;
Res := GetActiveObject(Word_TLB.CLASS_Application_,nil,unknown);
if (Res = MK_E_UNAVAILABLE) then
fapplication := CoApplication_.Create
else begin
OleCheck(Res);
OleCheck(Unknown.QueryInterface(_Application, MSWord));
end;
how do I set the fapplication-value in the case GetActiveObject returns a
value <> MK_E_UNAVAILABLE ?
Thanks
Glenn De Tollenaere
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.00001db7.059e2930 (AT) blueyonder (DOT) co.not-this-bit.uk...
|
|
| Back to top |
|
 |
Kim Doran Guest
|
Posted: Mon Nov 17, 2003 9:56 am Post subject: Re: Word automation |
|
|
Thanks, this is exactly the code I had been using. However when I attempt to
put Excel_TLB into my uses clause it cannot find it. Instead I use Excel97 -
this could the source of the problem. I don't appear to have Excel_TLB on my
machine. Any ideas where I can get it from?
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.00001db0.020ae4f6 (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Kim Doran:
Do you need to explicitly import anything to get this to
work
Here's the full Excel version, D5+. Hope it helps.
uses Windows, ComObj, ActiveX, Excel_TLB;
var
Excel: _Application;
AppWasRunning: boolean;
lcid: integer;
Unknown: IUnknown;
Result: HResult;
begin
lcid := LOCALE_USER_DEFAULT;
AppWasRunning := False;
Result :=
GetActiveObject(CLASS_ExcelApplication, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Excel := CoExcelApplication.Create
else begin
OleCheck(Result);
OleCheck(Unknown.QueryInterface(_Application, Excel));
AppWasRunning := True;
end;
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
|
| Back to top |
|
 |
Glenn De Tollenaere Guest
|
Posted: Mon Nov 17, 2003 10:19 am Post subject: Re: Word automation |
|
|
You need to import the type library (Projectmenu)
"Kim Doran" <kim.doran (AT) eircom (DOT) net> wrote
| Quote: | Thanks, this is exactly the code I had been using. However when I attempt
to
put Excel_TLB into my uses clause it cannot find it. Instead I use
Excel97 -
this could the source of the problem. I don't appear to have Excel_TLB on
my
machine. Any ideas where I can get it from?
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.00001db0.020ae4f6 (AT) blueyonder (DOT) co.not-this-bit.uk...
Kim Doran:
Do you need to explicitly import anything to get this to
work
Here's the full Excel version, D5+. Hope it helps.
uses Windows, ComObj, ActiveX, Excel_TLB;
var
Excel: _Application;
AppWasRunning: boolean;
lcid: integer;
Unknown: IUnknown;
Result: HResult;
begin
lcid := LOCALE_USER_DEFAULT;
AppWasRunning := False;
Result :=
GetActiveObject(CLASS_ExcelApplication, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Excel := CoExcelApplication.Create
else begin
OleCheck(Result);
OleCheck(Unknown.QueryInterface(_Application, Excel));
AppWasRunning := True;
end;
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
|
| Back to top |
|
 |
Kim Doran Guest
|
Posted: Mon Nov 17, 2003 10:32 am Post subject: Re: Word automation |
|
|
Thanks, I tried this but it doesn't appear that I have Excel8.olb on my
machine. Perhaps I need to reinstall Office?
"Glenn De Tollenaere" <gdt (AT) nospam (DOT) com> wrote
| Quote: | You need to import the type library (Projectmenu)
"Kim Doran" <kim.doran (AT) eircom (DOT) net> wrote in message
news:3fb89a6d$1 (AT) newsgroups (DOT) borland.com...
Thanks, this is exactly the code I had been using. However when I
attempt
to
put Excel_TLB into my uses clause it cannot find it. Instead I use
Excel97 -
this could the source of the problem. I don't appear to have Excel_TLB
on
my
machine. Any ideas where I can get it from?
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.00001db0.020ae4f6 (AT) blueyonder (DOT) co.not-this-bit.uk...
Kim Doran:
Do you need to explicitly import anything to get this to
work
Here's the full Excel version, D5+. Hope it helps.
uses Windows, ComObj, ActiveX, Excel_TLB;
var
Excel: _Application;
AppWasRunning: boolean;
lcid: integer;
Unknown: IUnknown;
Result: HResult;
begin
lcid := LOCALE_USER_DEFAULT;
AppWasRunning := False;
Result :=
GetActiveObject(CLASS_ExcelApplication, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Excel := CoExcelApplication.Create
else begin
OleCheck(Result);
OleCheck(Unknown.QueryInterface(_Application, Excel));
AppWasRunning := True;
end;
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Mon Nov 17, 2003 12:47 pm Post subject: Re: Word automation |
|
|
<
OleCheck(Unknown.QueryInterface(_Application, MSWord));
end;
how do I set the fapplication-value in the case
GetActiveObject returns a value <> MK_E_UNAVAILABLE ?
The call to QueryInterface has done that. You should be
able to use MSWord straight away.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Mon Nov 17, 2003 12:54 pm Post subject: Re: Word automation |
|
|
<
However when I attempt to put Excel_TLB into my uses clause
it cannot find it. Instead I use Excel97
That's fine, it's basically the same file preimported for
you by Borland.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
| Back to top |
|
 |
Kim Doran Guest
|
Posted: Mon Nov 17, 2003 1:41 pm Post subject: Re: Word automation |
|
|
Thanks Deborah, however I get the following message when it runs through the
QueryInterface call
EOleSysError with message 'The object exporter specified was not found'.
Calls to GetActiveObject(CLASS_ExcelApplication, nil, Unknown) and
CoExcelApplication.Create work fine which means it must be seeing the type
library OK.
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.00001dc1.007aa556 (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Kim Doran:
However when I attempt to put Excel_TLB into my uses clause
it cannot find it. Instead I use Excel97
That's fine, it's basically the same file preimported for
you by Borland.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Mon Nov 17, 2003 3:31 pm Post subject: Re: Word automation |
|
|
<
EOleSysError with message 'The object exporter specified
was not found'.
I've never seen that. Is it just on one machine? Did you
try reinstalling Excel?
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|