OpenHeaderSource Method
Attaches a mail merge header source to the specified document.
expression.OpenHeaderSource(Name, Format, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, OpenExclusive)
expression Required. An expression that returns a MailMerge object.
Name Required String. The file name of the header source.
Format Optional Variant. The file converter used to open the document. Can be one of the following WdOpenFormat constants. To specify an external file format, use the OpenFormat property with a FileConverter object to determine the value to use with this argument.
WdOpenFormat can be one of these WdOpenFormat constants. |
wdOpenFormatAllWord |
wdOpenFormatAuto Default. |
wdOpenFormatDocument |
wdOpenFormatEncodedText |
wdOpenFormatRTF |
wdOpenFormatTemplate |
wdOpenFormatText |
wdOpenFormatUnicodeText |
wdOpenFormatWebPages |
wdOpenFormatXML |
ConfirmConversions Optional Variant. True to display the Convert File dialog box if the file isn't in Microsoft Word format.
ReadOnly Optional Variant. True to open the header source on a read-only basis.
AddToRecentFiles Optional Variant. True to add the file name to the list of recently used files at the bottom of the File menu.
PasswordDocument Optional Variant. The password required to open the header source document. (See Remarks below.)
PasswordTemplate Optional Variant. The password required to open the header source template. (See Remarks below.)
Revert Optional Variant. 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.
WritePasswordDocument Optional Variant. The password required to save changes to the document data source. (See Remarks below.)
WritePasswordTemplate Optional Variant. The password required to save changes to the template data source. (See Remarks below.)
OpenExclusive Optional Variant. True to open exclusively.
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.
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. For recommended best practices on how to do this, see Security Notes for Microsoft Office Solution Developers.
Example
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