Author: Tomas Rutkauskas
I need to define some variables in a Word document and be able to set their values
from my Delphi program. How can I do that?
Answer:
You can do that using custom document properties:
1 uses2 Office97; {or Office2000, OfficeXP, Office_TLB}3 4 var5 VDoc, PropName, DocName: OleVariant;
6 VDoc := Word.ActiveDocument;
7 { ... }8 9 { Set a document property }10 PropName := 'MyOpinionOfThisDocument';
11 VDoc.CustomDocumentProperties.Add(PropName, False, msoPropertyTypeString,
12 'Utter drivel', EmptyParam);
13 { Read a document property }14 Caption := VDoc.CustomDocumentProperties[PropName].Value;
15 { ... }