Board index » delphi » OLE automation with Delphi 2.01 & Word 97

OLE automation with Delphi 2.01 & Word 97

Would someone know how to:

1- close Word upon finishing execution of a Delphi pgm which, at some
point, opened it using:
        ole := createOleObject('Word.application').
    I tried "ole.quit", which does not work, but does not cause an error
(what does it do?);
    I tried "old.close" too: same result...

2- how to detect that Word is running, and connect the OLE object with the
app that is already loaded in memory instead of starting a second instance?


Michel Ranger


Re:OLE automation with Delphi 2.01 & Word 97

This is one way, I'm sure there are others, to detect if word is running  

   temp := 'OpusApp';
       AHwnd :=  FindWindow(pchar(temp),nil);
       If (AHwnd = 0) then
              Temp := WhereisWord + '\winword.exe /n';
              AnAnswer := WinExec(pchar(temp), 1);
              If (AnAnswer < 32) then
                    Warning('Ole Handler', 'Unable to find WinWord.exe');

This is a piece of {*word*99} to link into the currently running word,
steal the application object from it and then go on.  This makes
a document which you then have to trash (unless you really wanted
a new blank document based on the normal template).  

         Basically := CreateOleObject('Word.Document.8');
         Warning('Ole Handler', 'Could not start Microsoft Word.');
         Result := False;
         Wordy := Basically.Application;
              Warning('Ole Handler', 'Could not access Microsoft Word.');
              Wordy := UnAssigned;
              Basically := UnAssigned;
   MyDocument := Wordy.ActiveDocument;
   (* when you close this, you get either no documents open
      or the document the user was working on*)

To get your little hooks out of word
    automationobject := Unassigned;

Other Threads