MailMerge.CreateHeaderSource method (Word)

Creates a Microsoft Word document that stores a header record that is used instead of the data source header record in a mail merge.

Syntax

expression. CreateHeaderSource( _Name_ , _PasswordDocument_ , _WritePasswordDocument_ , _HeaderRecord_ )

expression Required. A variable that represents a 'MailMerge' object.

Parameters

Name Required/Optional Data type Description
Name Required String The path and file name for the new header source.
PasswordDocument Optional Variant The password required to open the new header source.
WritePasswordDocument Optional Variant The password required to save changes to the new header source.
HeaderRecord Optional Variant A string that specifies the field names for the header record. If this argument is omitted, the standard header record is used: "Title, FirstName, LastName, JobTitle, Company, Address1, Address2, City, State, PostalCode, Country, HomePhone, WorkPhone." To separate field names in Microsoft Windows, use the list separator specified in Regional Settings in Control Panel.

Security

Important

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 Office solution developers.

Remarks

This method attaches the new header source to the specified document, which becomes a main document if it is not one already.The new header source uses a table to arrange mail merge field names.

Example

This example creates a header source with five field names and attaches the new header source named "Header.doc" to the active document.

ActiveDocument.MailMerge.CreateHeaderSource Name:="Header.doc", _ 
 HeaderRecord:="Name, Address, City, State, Zip"

This example creates a header source for the document named "Main.doc" (with the standard header record) and opens the data source named "Data.doc."

With Documents("Main.doc").MailMerge 
 .CreateHeaderSource Name:="Fields.doc" 
 .OpenDataSource Name:="C:\Documents\Data.doc" 
End With

See also

MailMerge Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.