Link to home
Start Free TrialLog in
Avatar of jpdupont
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?
Avatar of sassas081597
sassas081597

I did not test the code bellow. That is why I write a comment. If I am correct - you can ask me to write the answer.

procedure TForm1.Button1.Click(S: TObject);
begin
    V:=CreateOleObject('Word.Basic');
    If v.documents.count>0 then
       v.documents[1].activate
    else
       v.FileNew('Normal');
    v.Insert('I want to insert something there');
end;
Avatar of jpdupont

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.SpeedButton7Click(Sender: TObject);
var v:variant;
begin
   V := CreateOleObject('Word.Basic');
   V.AppShow;
   V.FileNew;
   if DataModule1.Table1NOMIMAGE.Value <>'' then
   begin     v.InsertPicture(REP_I_DATA+'\'+DataModule1.Table1NOMIMAGE.Value,true,false);
      V.Insert(#13+#13+DataModule1.Table1LEGENDE.Value);
   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
Avatar of sassas081597
sassas081597

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Its OK when WORD is loaded.
Error if Word isn't loaded !!!

Its OK when WORD is loaded.
Error if Word isn't loaded !!!

AS you see, I added TRY statement.
try
......
v.Insert('Hallo');
except
v:=CreateOleObject('Word.Basic');
.......
end;
v:=Null;
It's FINE !