Table in Header


2004-07-07 10:05:10 AM
delphi37
I am trying to insert a table with the page number in the first cell into
the header of my document using Word 2K and Delphi's Automation. This is my
Code:
procedure TForm1.Button1Click(Sender: TObject);
Var
Word: Word2000.TWordApplication;
Doc: Word2000._Document;
T: Word2000.Table;
R: Word2000.Range;
FieldPage: OLEVariant;
PageBreak: OLEVariant;
i: Integer;
begin
Word := Word2000.TWordApplication.Create(nil);
Word.Connect;
Word.Visible := TRUE;
FieldPage := wdFieldPage;
Doc := Word.Documents.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam);
R := Doc.Sections.Item(1).Headers.Item(1).Range;
T := R.Tables.Add(R, 1, 2, EmptyParam, EmptyParam);
R := T.Cell(1, 1).Range;
R.Fields.Add(R, FieldPage, EmptyParam, EmptyParam);
PageBreak := wdPageBreak;
R := Doc.Range(EmptyParam, EmptyParam);
For i := 0 to 3 do
R.InsertBreak(PageBreak);
end;
But I keep on getting an error saying that this COmmand is not avaliable? I
seem to bea able to set the cell's text to anything but as soon as I try to
add a field to the cell is doesn't work Does anyone have any ideas? It's
driving me nuts!
Grant