文档. Variables 属性 (Word)Document.Variables property (Word)

返回一个**variables** 集合, 该集合代表指定文档中存储的变量。Returns a Variables collection that represents the variables stored in the specified document. 此为只读属性。Read-only.

语法Syntax

expressionexpression. Variables

_表达式_一个代表**Document** 对象的变量。expression A variable that represents a Document object.

备注Remarks

有关返回集合中单个成员的信息, 请参阅返回集合中的对象For information about returning a single member of a collection, see Returning an object from a collection.

示例Example

本示例为活动文档添加一个名为"Value1"的文档变量。This example adds a document variable named "Value1" to the active document. 然后本示例查看 Value1 变量中的值,显示该值加 3 的结果。The example then retrieves the value from the Value1 variable, adds 3 to the value, and displays the results.

ActiveDocument.Variables.Add Name:="Value1", Value:="1" 
MsgBox ActiveDocument.Variables("Value1") + 3

本示例显示活动文档中每一文档变量的名称和值。This example displays the name and value of each document variable in the active document.

For Each myVar In ActiveDocument.Variables 
 MsgBox "Name =" & myVar.Name & vbCr & "Value = " & myVar.Value 
Next myVar

另请参阅See also

Document 对象Document Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.