MailMerge.OpenHeaderSource 方法 (Word)MailMerge.OpenHeaderSource method (Word)

将一个邮件合并域名源附加到指定文档。Attaches a mail merge header source to the specified document.

语法Syntax

expressionexpression. OpenHeaderSource( _Name_ , _Format_ , _ConfirmConversions_ , _ReadOnly_ , _AddToRecentFiles_ , _PasswordDocument_ , _PasswordTemplate_ , _Revert_ , _WritePasswordDocument_ , _WritePasswordTemplate_ , _OpenExclusive_ )

expression:必需。expression Required. 代表邮件合并对象的变量。A variable that represents a 'MailMerge' object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
NameName 必需Required StringString 域名源的文件名。The file name of the header source.
FormatFormat 可选Optional VariantVariant 用于打开文档的文件转换器。The file converter used to open the document. 可以是WdOpenFormat常量之一。Can be one of the WdOpenFormat constants. 若要指定外部文件格式,使用 FileConverter 对象的 OpenFormat 属性来确定要使用该参数的值。To specify an external file format, use the OpenFormat property with a FileConverter object to determine the value to use with this argument.
ConfirmConversionsConfirmConversions 可选Optional VariantVariant True 显示 转换文件对话框中,如果该文件不是 Microsoft Word 格式。True to display the Convert File dialog box if the file isn't in Microsoft Word format.
ReadOnlyReadOnly 可选Optional VariantVariant 要打开域名源在唯读的基础上。True to open the header source on a read-only basis.
AddToRecentFilesAddToRecentFiles 可选Optional VariantVariant 要将文件名添加到列表中最近使用的文件在 文件菜单的底部。True to add the file name to the list of recently used files at the bottom of the File menu.
PasswordDocumentPasswordDocument 可选Optional VariantVariant 打开域名源文档所需的密码。The password required to open the header source document. 请参阅下面的"说明")。(See Remarks below.)
PasswordTemplatePasswordTemplate 可选Optional VariantVariant 打开域名源模板所需的密码。The password required to open the header source template. 请参阅下面的"说明")。(See Remarks below.)
RevertRevert 可选Optional VariantVariant 控制如果 Name 是已打开文档的文件名,会发生什么情况。Controls what happens if Name is the file name of an open document. 真正 放弃对已打开文档任何未保存的更改并重新打开该文件; 以激活打开的文档。True to discard any unsaved changes to the open document and reopen the file; False to activate the open document.
WritePasswordDocumentWritePasswordDocument 可选Optional VariantVariant 将更改保存到文档数据源所需的密码。The password required to save changes to the document data source. 请参阅下面的"说明")。(See Remarks below.)
WritePasswordTemplateWritePasswordTemplate 可选Optional VariantVariant 将更改保存到模板数据源所需的密码。The password required to save changes to the template data source. 请参阅下面的"说明")。(See Remarks below.)
OpenExclusiveOpenExclusive 可选Optional VariantVariant 真正 以独占方式打开。True to open exclusively.

安全Security

尽量避免在应用程序中使用硬编码的密码。Avoid using hard-coded passwords in your applications. 如果过程中需要使用密码,请向用户请求密码并将其存储在一个变量中,然后在代码中使用该变量。If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code. 有关执行此操作的建议最佳实践,请参阅 Microsoft Office 解决方案开发人员安全注意事项For recommended best practices on how to do this, see Security Notes for Microsoft Office Solution Developers.

备注Remarks

附加一个域名源时,域名源中的第一个记录将替换数据源中的域名记录。When a header source is attached, the first record in the header source is used in place of the header record in the data source.

示例Example

本示例将活动文档设置为套用信函的主文档,然后为其附加名为"Header.doc"的域名源和名为"Names.doc"的数据文档。This example sets the active document as a main document for form letters, and then it attaches the header source named "Header.doc" and the data document named "Names.doc."

With ActiveDocument.MailMerge 
 .MainDocumentType = wdFormLetters 
 .OpenHeaderSource Name:="C:\Documents\Header.doc", _ 
 Revert:=False, AddToRecentFiles:=False 
 .OpenDataSource Name:="C:\Documents\Names.doc" 
End With

另请参阅See also

邮件合并对象MailMerge Object