
The following example adds a document variable named "Temp" with a value of 12 to the active document. Use the Add method of the Variables collection to add a variable to a document. The following example displays the name of the first document variable in the active document. 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.

The index number represents the position of the document variable in the Variables collection. MsgBox ActiveDocument.Variables("Temp").Value The following example displays the value of the Temp document variable in the active document. Use Variables (Index), where Index is the document variable name or the index number, to return a single Variable object. The Variables collection includes all the document variables in a document or template. The Variable object is a member of the Variables collection.

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