Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a parameter to a OLE Automation object such as MS Word

This is mainly a Delphi syntax related question. I need to set a parameter to True when calling a method of an OLE object.

I need to set in Word Automation (this is from Word Reference):

wdApp.Quit SaveChanges:=wdDoNotSaveChanges

As an example a dummy procedure where I would like to do this follows (please note WordApp.Quit!):

Procedure GetWordVersion;
    var
      WordApp: OLEVariant;
    begin
      { Create the OLE Object }
      Try
          WordApp := CreateOLEObject('Word.Application');
          WordVersion := WordApp.version;
           WordApp.Quit; // >-- HERE!!!!
      except
        on E: Exception do
        begin
          WordVersion := -1;
        end;
      End;
end;

Here (check the accepted answer) the same thing seems to be done, but if I try it it:doesn't compile. I copy here only the relevant parts:

Const wdDoNotSaveChanges = 0
[...]

  wdo.Quit wdDoNotSaveChanges 

[...]

End Function

Important: instead of using

// this is from Word Reference    
wdApp.Quit SaveChanges:=wdDoNotSaveChanges

it is possible to use

// from Word Reference
wdApp.NormalTemplate.Saved = True

Could anyone please modify my GetWordVersion procedure above so that either one of the 2 approaches above are used? Thanks.

like image 361
LaBracca Avatar asked Feb 21 '23 09:02

LaBracca


1 Answers

You can write:

Wordapp.Quit(SaveChanges:=wdDoNotSaveChanges);

Or use this:

word := CreateOleObject('Word.Application'); 

.... 
word.DisplayAlerts := false;
word.Quit; 
like image 141
Lars Avatar answered Apr 07 '23 18:04

Lars