Newbie question about Mail Merge and macros

C

Charles Freeman

Word gurus, a bit of advice, please:

I am a database programmer with an app written in xBase++, a C-like
language. I know virtually nothing about Word, especially templates, macros,
and VBA.

I want to be able to (a) Edit mail merge templates and (b) perform mail
merges from within my database app by launching Word. I would like this to
work with any Word version from 2000 up. Here is my proposed architecture:

Edit:
1) Within the database app, the user selects a Word template file from a
list. .
2) The database app creates the data source as a .CSV file with the same
name as the .DOT template which contains one record, the merge field names.
3) Word is launched from the database app with the specified template as a
command line parameter. The user can edit and save the template.

Merge:
4) Within the database app, the user selects a Word template file from a
list. They also select the data record(s) to merge from within the internal
encrypted database.
5)* The database app creates a copy of the template, renaming it as a
temporary file name.
6) The database app "cooks" the data records, creating a .CSV file which
contains the header AND unencrypted data field(s) with the same temporary
file name root..
7)* The database app does a raw file edit of the template, finding the
original merge data source filename and replacing it with the new temporary
merge source filename.
8) Word is launched with the temporary template AND some sort of macro name
(which causes the merge to occur) as command line parameters.

* These steps are implemented because as far as I can tell Word embeds a
permanent data source name within the template itself, which cannot be
passed as a command line parameter to Word. I need to be able to run on a
network with multiple simultaneous access, so by doing it this way the users
don't bump one another.

I'm sure I'm not the first person down this merry path, and many of you will
have lots of helpful hints and suggestions for me on how I REALLY ought to
do it. ;-)

Many thanks,

Charlie
 
C

Cindy M -WordMVP-

Hi Charles,
2) The database app creates the data source as a .CSV file with the same
name as the .DOT template which contains one record, the merge field names.
3) Word is launched from the database app with the specified template as a
command line parameter. The user can edit and save the template.
With more recent versions of Word you may run into problems with having only
one record. Create two records in the CSV file, instead; both can simply
consist of the field names. The second one will act as a "confirmation" to
Word for the field delimiter.

I'm seeing more problems with the proposed approach for the "Merge" part.
1. Templates in Word are meant for creating new documents, not for being
"used" directly. So if you're planning to work as you describe, you should be
working with .doc files, not templates.

2. Can your database app use COM to automate other applications? That would
certainly be the best way to get around the limitations you mention. I
certainly would NOT recommend trying to change the file name in Word by
manipulating the "raw file".

3. If your database app does not support this, alternatives would be:
- macros in the templates that can control attaching/removing data sources
- a VB6 (or Delphi, or .NET - IOW anything that does support COM) app to take
care of the steps your database app cannot
Merge:
4) Within the database app, the user selects a Word template file from a
list. They also select the data record(s) to merge from within the internal
encrypted database.
5)* The database app creates a copy of the template, renaming it as a
temporary file name.
6) The database app "cooks" the data records, creating a .CSV file which
contains the header AND unencrypted data field(s) with the same temporary
file name root..
7)* The database app does a raw file edit of the template, finding the
original merge data source filename and replacing it with the new temporary
merge source filename.
8) Word is launched with the temporary template AND some sort of macro name
(which causes the merge to occur) as command line parameters.

* These steps are implemented because as far as I can tell Word embeds a
permanent data source name within the template itself, which cannot be
passed as a command line parameter to Word. I need to be able to run on a
network with multiple simultaneous access, so by doing it this way the users
don't bump one another.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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