jpdupont
asked on
OLE with Word
In one of my softwares, I use OLE to transfer data into a Word file. Each time I use this code, I open a NEW Word window. How can I insert the data in the ACTIVE DOCUMENT if Word is already open?
ASKER
Your code give the error :
"'documents' method non supported by automation object"
(in french : "Méthode 'documents' non supportée par l'objet automation'"
I use DELPHI 3 in french
WORD97 french
My code :
=========
procedure TPHOTOTHEQUE.SpeedButton7C lick(Sende r: TObject);
var v:variant;
begin
V := CreateOleObject('Word.Basi c');
V.AppShow;
V.FileNew;
if DataModule1.Table1NOMIMAGE .Value <>'' then
begin v.InsertPicture(REP_I_DATA +'\'+DataM odule1.Tab le1NOMIMAG E.Value,tr ue,false);
V.Insert(#13+#13+DataModul e1.Table1L EGENDE.Val ue);
end;
==========
works fine but always open a NEW Word window. How can I insert the data in the ACTIVE DOCUMENT if Word is
already open?
"'documents' method non supported by automation object"
(in french : "Méthode 'documents' non supportée par l'objet automation'"
I use DELPHI 3 in french
WORD97 french
My code :
=========
procedure TPHOTOTHEQUE.SpeedButton7C
var v:variant;
begin
V := CreateOleObject('Word.Basi
V.AppShow;
V.FileNew;
if DataModule1.Table1NOMIMAGE
begin v.InsertPicture(REP_I_DATA
V.Insert(#13+#13+DataModul
end;
==========
works fine but always open a NEW Word window. How can I insert the data in the ACTIVE DOCUMENT if Word is
already open?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Its OK when WORD is loaded.
Error if Word isn't loaded !!!
Error if Word isn't loaded !!!
ASKER
Its OK when WORD is loaded.
Error if Word isn't loaded !!!
Error if Word isn't loaded !!!
AS you see, I added TRY statement.
try
......
v.Insert('Hallo');
except
v:=CreateOleObject('Word.B asic');
.......
end;
v:=Null;
try
......
v.Insert('Hallo');
except
v:=CreateOleObject('Word.B
.......
end;
v:=Null;
ASKER
It's FINE !
procedure TForm1.Button1.Click(S: TObject);
begin
V:=CreateOleObject('Word.B
If v.documents.count>0 then
v.documents[1].activate
else
v.FileNew('Normal');
v.Insert('I want to insert something there');
end;