Author: Lou Adler
Can someone tell me how to set the text in footers of MS Word documents
programmatically from inside D5? I can create and open the document. I think it has
to do with the BuiltInDocumentProperties. However, I cannot find a property for the
document footer. Any ideas?
Answer:
Solve 1:
You can't access the header/ footer via BuiltInDocumentProperties. Use this instead:
Footer:
1 { ... }2 aDoc := WordApp.Documents.Add(EmptyParam, EmptyParam);
3 aDoc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range.Text :=
4 'This is a footer';
5 { ... }
Header:
6 { ... }7 aDoc := WordApp.Documents.Add(EmptyParam, EmptyParam);
8 aDoc.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary).Range.Text :=
9 'This is a header';
10 { ... }
Solve 2:
This works with Word 2000, and I can't remember it having changed since Word 97,
anyway. If Doc is your Word document:
11 { ... }12 var13 Hdr: HeaderFooter;
14 { ... }15 Hdr := Doc.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary);
16 Hdr.Range.Text := 'This is a header';
17 { ... }