Board index » delphi » OleAuto, Word 8, Number of pages in document

OleAuto, Word 8, Number of pages in document

Delphi 2, OleAuto, Word 8, Number of pages in document

How can I read the number of pages in the active document of Word 97?

I am using Delphi Developer version 2.
My program is working as an Ole-Automation client with MS Word 97 working as
the Ole-Automation server.
Things are running perfect as long as I only call methods.
This is illustrated in the following code:

unit MyUnit;
uses OLEAuto;
var    W : Variant;


function MyFunction
var
  NumPages : word;
  WordVersion : string;
begin
  try
    W := GetActiveOleObject('Word.Application');
  except
    W := CreateOleObject('Word.Application');
  end;
  WordVersion := W.Application.Version; {get the version number}
 
  {other code}
 
  {The next line doesnt work:}
  NumPages := W.ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
end;

The last code line does not work. It generates an exception
BuiltInDocumentProperties is not a method. It seems that I can only use
methods and that properties cannot be read.
Can someone explain me how I can read the number of pages of the active Word
document into my Delphi application?
Alfred Hoks
alh...@worldonline.nl

 

Re:OleAuto, Word 8, Number of pages in document


The following works for me:

function TForm1.MyFunction: integer;
var
  W: variant;
begin
  Result := 0;
  try
    W := GetActiveOleObject('Word.Basic');
  except
    W := CreateOleObject('Word.Basic');
  end;
  W.FileOpen('c:\CV.doc');
  Result := W.GetDocumentProperty('Pages');
end;

Incidentally, if you've got MSOffice installed on your machine, you should find
WrdBasic.hlp in a subdirectory - on my machone c:\MSOffice\Winword

Charles Johnson

Other Threads