I am buliding a delphi form to add a new word document in MS Word and wait for the user to insert text and edit document, save the file and exit form MS Word, then get me the file name and path to the file.
WordApp := CreateOleObject('Word.Application');
WordApp.Visible := True;
Doc := WordApp.Documents.add();
wait for user insert text and edit document and save file and exit form MS Word THEN
Doc.Save;
DocName := Doc.Name;
Docpath := IncludeTrailingPathDelimiter(Doc.path) + DocName;
with ZipForge1 do
begin
FileName := Zipfilename;
OpenArchive;
Options.StorePath := spNoPath;
AddFiles(Docpath);
CloseArchive;
end;
You could write your own event sink to listen to the Word application’s
OnQuitevent. However, it’s going to be easier to switch to early bound COM. The import type library, found inWord2000.pas, contains all that you need.TWordApplicationfor your application object.OnDocumentBeforeCloseandOnQuit.To illustrate, here’s the most trivial example that I can devise: