Variables.Add Method
Word Developer Reference |
Returns a Variable object that represents a variable added to a document.
Syntax
expression.Add(Name, Value)
expression Required. A variable that represents a Variables collection.
Parameters
Name | Required/Optional | Data Type | Description |
---|---|---|---|
Name | Required | String | The name of the document variable. |
Value | Optional | Variant | The value for the document variable. |
Return Value
Variable
Remarks
Document variables are invisible to the user unless a DOCVARIABLE field is inserted with the appropriate variable name. If you try to add a 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 a new variable to it.
Example
This example adds a variable named Temp to the active document and then inserts a DOCVARIABLE field to display the value in the Temp variable.
Visual Basic for Applications |
---|
|
This example sets the value of the Blue variable to six. If this variable doesn't already exist, the example adds it to the document and sets it to six.
Visual Basic for Applications |
---|
|
This example stores the user name (from the Options dialog box) in the template attached to the active document.
Visual Basic for Applications |
---|
|
See Also