Represents a variable stored as part of a document. Document variables are used to preserve macro settings in between macro sessions.
Assembly: Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)
The Variable object is a member of the Variables collection. The Variables collection includes all the document variables in a document or template.
Use Variables(index), where index is the document variable name or the index number, to return a single Variable object.
The index number represents the position of the document variable in the Variables collection. The last variable added to the Variables collection is index number 1; the second-to-last variable added to the collection is index number 2, and so on.
If you try to add a document variable with a name that already exists in the Variables collection, an error occurs. To avoid this error, you can enumerate the collection before adding any new variables.
Document variables are invisible to the user unless a DOCVARIABLE field is inserted with the appropriate variable name.
To add a document variable to a template, open the template as a document by using the OpenAsDocument method.