Variable Interface

Represents a variable stored as part of a document. Document variables are used to preserve macro settings in between macro sessions.

Namespace:  Microsoft.Office.Interop.Word
Assembly:  Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)

[GuidAttribute("00020966-0000-0000-C000-000000000046")]
public interface Variable

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.

Use the Add of the Variables collection method to add a variable to a document.

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.

Community Additions

ADD
Show:
© 2014 Microsoft