Create related procedures in class MailMerge (Word VBA)

This page presents procedures from class MailMerge related to the theme Create: CreateDataSource and CreateHeaderSource

CreateDataSource

Creates a Microsoft Word document that uses a table to store data for a mail merge.

When you use the CreateDataSource method, Word attaches the new data source to the specified document, which becomes a main document, if it is not one already. How you specify the range for the Connection argument depends on how data is retrieved. For example:

Syntax : expression.CreateDataSource (Name, PasswordDocument, WritePasswordDocument, HeaderRecord, MSQuery, SQLStatement, SQLStatement1, Connection, LinkToSource)

ActiveDocument.MailMerge.CreateDataSource _ 
 Name:="C:\Documents\Data.doc", _ 
 HeaderRecord:="Name, Address, City, State, Zip"

Arguments

The following arguments are optional

Name (String) - The path and file name for the new data source.

PasswordDocument (Source) - The password required to open the new data source.

WritePasswordDocument (Source) - The password required to save changes to the data source.

HeaderRecord (String) - 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, use the list separator specified in Regional Settings in Control Panel.

MSQuery (Boolean) - True to launch Microsoft Query, if it is installed. The Name, PasswordDocument, and HeaderRecord arguments are ignored.

SQLStatement (String) - Defines query options for retrieving data.

SQLStatement1 (String) - If the query string is longer than 255 characters, SQLStatement specifies the first portion of the string, and SQLStatement1 specifies the second portion.

Connection (Range) - A range within which the query specified by SQLStatement will be performed.

LinkToSource (Boolean) - True to perform the query specified by Connection and SQLStatement each time the main document is opened.

CreateHeaderSource

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

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.

Syntax : expression.CreateHeaderSource (Name, PasswordDocument, WritePasswordDocument, HeaderRecord)

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

Arguments

The following argument is required

Name (String) - The path and file name for the new header source.

The following arguments are optional

PasswordDocument (String) - The password required to open the new header source.

WritePasswordDocument (String) - The password required to save changes to the new header source.

HeaderRecord (String) - 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.