PreviousNext
Help > Programming with LAUNCHER Office > LNCCMD commands > Commands list > WMAILMERGE command
WMAILMERGE command

Performs a merge between the Word template and the data file.

This command uses Word merge fields.

 

Syntax

 

CHGVAR

VAR(&CMD) VALUE('WMAILMERGE')

CHGVAR

VAR(&PARM1) VALUE('
[Document="model name"]

[;Destination=constant]

[;SaveAs="saved document name"]
[;SaveAsFmt=constant]

[;DataSource="data source"]

[;HeaderSource="headers file"]

[;FirstRecord= value]

[;LastRecord= value]

[;SuppressBlankLines=True/False]

[;SourceFormat= value]

[;HeaderFormat= value]

[;Type=constant]

[;Execute=True/False ]

[;MailAddress="field for recipient address"]

[;MailSubject="message subject"]

[;AsAttachment=True/False]

[;OneDoc=True/False]

')

CHGVAR

VAR(&PARM2) VALUE(' ')

CALL

PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 +

&PARM2 &RESULT)

MONMSG

MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

Parameters

 

Parameters

 

Parm1

Document: name of the main document, if this parameter is empty the current document will be considered as main document. If it has been initialized by a first merge operation, it is retained.

Destination: destination of the merge, can be one of the following constants:

wdSendToEmail, for sending by email. Fill in the MailAddress parameter.

wdSendToFax, for sending by fax.

wdSendToNewDocument, to create a new document (default value). Fill in the SaveAS parameter.

wdSendToPrinter, for sending to the printer.

lncSendToFile, to save each letter to an individual file. The SaveAs parameter must then contain a path and rules for constructing a unique filename for each letter.

SaveAs: Path and name of the file where to save the result of the merge.
If Destination = lncSendToFile, or OneDoc=true, then the file name specified by the SaveAs parameter must be constructed from field values
​​of the data source.

SaveFmt: wdFormatXMLDocument / wdFormatDocument / wdFormatDOSText / wdFormatDOSTextLineBreaks / wdFormatEncodedText / wdFormatHTML / wdFormatRTF / wdFormatTemplate / wdFormatText / wdFormatTextLineBreaks / wdFormatUnicodeText.

If this parameter is not specified, the default Word format is used.
For example, for Word 2019, this is the format wdFormatXMLDocument (DOCX).
To save in PDF format (from Word 2010) we can use the value 17.

DataSource: name of the source file. This parameter is not required if the main document already contains the name of the associated data source.

HeaderSource : name of the file that contains the headers. Allows you to specify a separate source that contains the name of the column headers (and which appear in the main document as merge fields).

FirstRecord: Number of the first record of the data source to use for the mail merge.
If this parameter is not specified, the first record of the data source is taken into account.

LastRecord: The number of the last record of the data source to use for the mail merge.
If this parameter is not specified, the last record of the data source is taken into account.

SuppressBlankLines, indicates whether to keep empty lines or not, after the merge. Default: true.

SourceFormat, HeaderFormat indicate the format of the source file and the header file, respectively.
The possible values
​​are:

wdOpenFormatAllWord, wdOpenFormatAuto, wdOpenFormatDocument, wdOpenFormatEncodedText, wdOpenFormatRTF, wdOpenFormatTemplate, wdOpenFormatText, wdOpenFormatUnicodeText, or wdOpenFormatWebPages.
The default value is: wdOpenFormatAuto.

Type : type of merge document. The possible values ​​are:
wdCatalog, wdEnvelopes, wdFormLetters (default), wdMailingLabels, wdNotAMergeDocument.

Execute (Default execute = true): If "execute = false", the document is simply prepared for a merge, but not merged.

Onedoc = true equals "Destination = lncSendToFile", to save each letter to an individual file. The SaveAs parameter must then contain a path and rules for constructing a unique filename for each letter. Default: false.

If the destination is an email (wdSendToEmail), then the following properties can be set:

MailAddress: Refers to the field of the DataSource file containing the recipient's address.

MailSubject: Subject of the email message.

AsAttachment: indicates that the document should be attached to the message. Default: false.

 

 

Notes

 

1) No parameter is required.

2) If the main document has been prepared for a merge, it contains the name of the data source and the destination, it can then be opened by the WDOCUMENT command before using the WMAILMERGE command without any parameters.

The main document type allows you to modify the characteristics of the merge, the different types are: standard letters, labels, envelopes, catalog (no page breaks between two recordings). It must be defined when preparing the main document.

 If a first operation has initialized the values ​​of the main document, the data source and the destination, we can restart a WMAILMERGE which will take all these parameters. For example, to merge only a particular record or range of records.

 

3)

The "Execute = False" property allows you to programmatically prepare a merge document, attaching the data source to it, without executing it.

Once the fusion document is prepared, possibly empty, the program can present it to the user (WORDSHOW) so that the latter can compose it.

 

 4)

Construct a file name from a field in the data source:

When Destination = lncSendToFile is specified, or when OneDoc = true, each letter is saved to a file. The path and file name given by the SaveAs keyword can contain references to fields in the data source. The field to which reference is made must be between characters <and>.

Example:
Destination=lncSendToFile; SaveAs="D:\ Letters\ Prop_<CUST_ID>.DOCX";

In this example, each letter will be saved in the sub-directory "Letters", and the name will be composed of the word "Prop_" followed by the value of the field "CUST_ID".

 

Example

 

VAR(&CMD) VALUE('WMAILMERGE')

CHGVAR

VAR(&PARM1) VALUE('Document="C:\chemin\maitre.docx" ;+

Destination="wdSendToEmail";+

MailAddress="tech@easycom-aura.com"')

CHGVAR

VAR(&PARM2) VALUE(' ')

CALL

PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 +

&PARM2 &RESULT)

MONMSG

MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

 

 

Merge the main document "Master.docx" with the data source that is already associated with it and send the result by mail to AURA Equipements technical service.

 

CHGVAR

VAR(&CMD) VALUE('WMAILMERGE')

CHGVAR

VAR(&PARM1) VALUE('Document="C:\chemin\maitre.docx" ;+

DataSource="C:\chemin\SPCUST.txt";+

SaveAs="result_5_6.docx";FirstRecord=5;+

LastRecord=6')

CHGVAR

VAR(&PARM2) VALUE(' ')

CALL

PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 +

&PARM2 &RESULT)

MONMSG

MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

CHGVAR

VAR(&CMD) VALUE('WMAILMERGE')

CHGVAR

VAR(&PARM1) VALUE(‘SaveAS="Result_17_20.docx"+

FirstRecord=17;LastRecord=20')

CHGVAR

VAR(&PARM2) VALUE(' ')

CALL

PGM(LNCCMD) PARM(&HANDLE &CMD &OPT &PARM1 +

&PARM2 &RESULT)

MONMSG

MSGID(LNC0000) EXEC(GOTO CMDLBL(ERROR))

 

Prepares the merging of the spcust.txt data source with the main document, merges the records 5 and 6 to the result_5_6.docx document and then merges, with the same elements, the records 17 to 20.

 

     LNCCMD     CMD(WMAILMERGE) +                               

                 PARM1('DOCUMENT="C:\temp\test\+  

                 sp_cust.dotx";DATASOURCE="C:\temp\test+  

                 \csv2.TXT";SAVEAS="C:\temp\res\+  

                 res_<CUST_ID>.pdf";OneDoc=true;SaveFmt=17') 

 

Executes the merge using the specified model and data source. A PDF will be generated (based on the template) for each record.

 

See also

 

LNCPRTDOC - Commande CL

DBXFER

Create a merge file