MailMergeFields.AddSet 方法 (Word)MailMergeFields.AddSet Method (Word)

向邮件合并主文档添加一个 SET 域。Adds a SET field to a mail merge main document. 返回一个MailMergeField对象。Returns a MailMergeField object.

语法Syntax

expressionexpression. AddSet( _Range_ , _Name_ , _ValueText_ , _ValueAutoText_ )

expression:必需。expression Required. 代表MailMergeFields集合的变量。A variable that represents a 'MailMergeFields' collection.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
RangeRange 必需Required Range objectRange object SET 域的位置。The location for the SET field.
NameName 必需Required StringString 向其分配 ValueText 的书签名称。The bookmark name that ValueText is assigned to.
ValueTextValueText 可选Optional VariantVariant 与 Name 参数指定的书签名称相关的文字。The text associated with the bookmark specified by the Name argument.
和 ValueAutoTextValueAutoText 可选Optional VariantVariant 包含与 Name 参数指定的书签相关的文字的"自动图文集"词条。The AutoText entry that includes text associated with the bookmark specified by the Name argument. 如果指定该参数,则忽略 ValueText。If this argument is specified, ValueText is ignored.

返回值Return value

MailMergeFieldMailMergeField

注解Remarks

SET 域定义指定书签的文字。A SET field defines the text of the specified bookmark.

示例Example

本示例在活动文档的开头添加一个 SET 域,然后添加一个 REF 域,显示选定后的文字。This example adds a SET field at the beginning of the active document and then adds a REF field to display the text after the selection.

Dim rngTemp as Range 
 
Set rngTemp = ActiveDocument.Range(Start:=0, End:=0) 
 
ActiveDocument.MailMerge.Fields.AddSet Range:=rngTemp, _ 
 Name:="Name", ValueText:="Joe Smith" 
Selection.Collapse Direction:=wdCollapseEnd 
ActiveDocument.Fields.Add Range:=Selection.Range, _ 
 Type:=wdFieldRef, Text:="Name"

另请参阅See also

MailMergeFields 集合对象MailMergeFields Collection Object