Command line MailMerge

P

PMTRCPMTRC

Is it possible to issue a command from the command line that would load a Word template file (.dot) and automatically merge it with a text data file (.txt) and display the merged result to the user?

PMC
 
D

Doug Robbins

Check out the "Customize how Word starts" item in the built in Help to see
how to add a switch the command line (in this case \t) to have Word start
with a new document based on a particular particular template. If that
template has an autonew macro in it to execute the merge, then you will have
what you want. Check out Mailmerge in the Visual Basic help file to get the
commands and syntax that you will need for the macro.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
Is it possible to issue a command from the command line that would load a
Word template file (.dot) and automatically merge it with a text data file
(.txt) and display the merged result to the user?

PMC
 
P

Peter Jamieson

A couple of additions to Doug's post: If you want to specify the data source file on the command line
a. your macro will need to get the complete command line using whatever facilities are available (you may need to use a Win32 function to do it).
b. because Word tries to find any attached data source before it even executes things such as AutoNew and AutoOpen, and because you cannot trap the error if the data source is not present or is invalid, you must either
- ensure that the data source the document expects is there. Once Word has attached it, your macro can change it or
- detach the document/template from the data source before you save it, i.e. set the document/template to be a "Normal Word document". You will lose any sort or filter parameters, but MERGEFIELD and other merge-related fields should still remain.

--
Peter Jamieson

Is it possible to issue a command from the command line that would load a Word template file (.dot) and automatically merge it with a text data file (.txt) and display the merged result to the user?

PMC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top