MailMergeState()

Syntax

MailMergeState(Type)

Remarks

Returns one of four different types of information about the current state of a mail-merge setup. Type 1, Type 2, and Type 3 return –1 if the active document is not a main document, data source, or header source.

Type

Values and descriptions

0 (zero)

Returns information about the active document:

0 (zero) Regular Word document

1 Main document with no data or header source attached

2 Main document with an attached data source

3 Main document with an attached header source

4 Main document with both a data and header source attached

5 Data source or header source; associated main document is open

1

Returns the kind of main document:

0 (zero) Form letters

1 Mailing labels

2 Envelopes

3 Catalog

2

Returns information about the selected mail-merge options:

0 (zero) Neither blank-line suppression nor query options are enabled.

1 Blank-line suppression is enabled.

2 Query options are enabled.

3 Both blank-line suppression and query options are enabled.

3

Returns the mail-merge destination:

0 (zero) New document

1 Printer

2 Electronic mail

3 Fax


Example

This example checks the state of the active document before performing a mail merge. If the active document is not a main document, Word displays a message box. If the document is a main document but has no attached data source, a data source is attached. In any other case, the mail merge begins immediately.


Select Case MailMergeState(0)
    Case 0
        MsgBox "Not a mail merge main document."
        quitmacro = 1
    Case 1, 3
        MailMergeOpenDataSource .Name = "C:\DATA\DATA.DOC"
    Case Else
End Select
If quitmacro = 1 Then Goto bye
MailMergeToPrinter
bye:

See Also

MailMergeMainDocumentType