|
|
|
|
|
Many people access the material from this web site daily. Most just take what they want and run. That's OK, provided they are not selling on the material as their own; however if your productivity gains from the material you have used, a donation from the money you have saved, however small, would help to ensure the continued availability of this resource.
Click the
appropriate button above
to access PayPal. |
|
'Many-to-One' mail merge |
| |
The mail
merge function in Microsoft Word works only with a flat data file as a
'One-to-One' merge i.e. a separate document for each record.
There have been various approaches proposed to enable
the merging of lists associated with records that share a common 'key'
field - for example a list of purchased items from a particular customer
where multiple separate product items are associated with each customer. Microsoft's own
suggested approach is quite complicated and recorded at
How to use mail
merge to create a list sorted by category
Fellow Word MVP Paul Edstein has posted a tutorial on this, with working
field codes and a sample Excel data source which you can
download
from this web site but it can be a tad bewildering and even Paul
would concede that creating this type of merge can be intimidating for
those unskilled in mail merge.
To overcome
this difficulty another Antipodean MVP and occasional contributor to this
site, Doug Robbins, produced an add-in to attempt to simplify the
process. I developed the principles Doug had come up with to form the basis of
an add-in,
the use of which is described on this page.
The
original versions of the add-in
have not been without problems. In an effort to reduce some of the issues
users have experienced, the add-in was completely
redeveloped for Version 3.0
The add-in
is supplied in DOTM template format for Word 2007/2010 and includes a modification to the Mailings Tab of the ribbon.
The add-in requires the data source used for the merge
to be in Excel format, with Outlook as the default e-mail application
for Windows. Where Outlook is not available, the options to merge to
e-mail will not be available. The function uses the Shell32.DLL object
library to determine whether Outlook is available. With some operating
systems, notably Windows 7 - 64 bit, Shell32.DLL may not be available by
default and thus produce an error when the function is started. Where that is an issue,
download the explanatory document, which should help you resolve it. |
|
Notes: |
If
there are likely to be some rows with no data in some of the Excel data
source fields, all
of the cells that represent the data source must be formatted as text.
Otherwise, errors can occur, when the routine encounters a type of data
that it is not expecting.
The data
must be sorted by the field that is going to be used as the key field. Not sorting it that way will not cause an error, but the desired result
will not be achieved.
When merging to e-mail,
ensure that the e-mail addresses are in a valid format and that all the
records have a valid e-mail address. The add-in will detect invalid
e-mail addresses. Where records do not have a valid e-mail
address you must correct the address, replace it with a valid address
(such as your own e-mail address) or use a dummy
address as in the example data supplied with the add-in.
When merging to e-mail,
the application should start Outlook, if it is not already running, but
such is the relationship between the Office products that this may not
happen. It is therefore advisable to start Outlook before running the
application.
The
appropriate add-in should be
should be extracted to the Word
start-up folder. By default the start-up folder location is a hidden
location, but it can easily be located by typing %appdata%\Microsoft\Word\Startup
in the address bar of Windows Explorer or your Internet Explorer browser.
Alternatively you can use the self extracting installer that is also
supplied in the download file.
When Word is run
the add-in will load and the three buttons will be added to the mailings tab of the ribbon. |
|
 |
| MERGE 'MANY-TO-ONE' |
|
|
For the
purpose of explanation of the use of the add-in, a sample merge document and an Excel data source
are included in the zip file. An extract of the
relevant part of the merge document is included below.
The merge document must
be set up as a conventional letter merge.
While testing the
e-mail options with the sample data source, it is advisable to configure Outlook not to
send messages immediately!
The messages created by
the application will go to a sub folder of the Outlook Drafts folder
called 'Merge Many To One'. Messages are only sent when you choose to
send them. If you have the option set to send messages immediately when
connected, then that is exactly what will happen, so do not do that
unless you really do want to send the messages to the recipients
indicated in the data file. The example data supplied with add-in
contains dummy e-mail addresses and so it will not matter too much if
you send the messages. They will only be bounced back with a delivery
failure error.
With the
example document, the 'Key field' is OWNER and the 'Child fields'
are PROP_ID, LEGAL_DESC. and for the totalled fields
ACRES and VALUE
The fields
are inserted in the document as shown in the upper illustration. They do
not have to be placed in a table, but a table format is ideal for lists.
The intended result
is shown in the lower illustration of the two illustrations that
immediately follow. Note that only one set of each of the “repeating”
fields (PROP_ID, LEGAL_DESC, ACRES and VALUE) is required in each
location where that data may be reproduced as shown in the table of the
first illustration. The fields not designated as child fields will be
reproduced from the first record that matches the key field. In the
example document, those are the fields of the address. |
| Totalling the values in the
columns. |
|
|
With lists
of items, it is often desirable to provide a total of the values of one
of more of the listed fields. This can be done quite simply, subject to
two provisos.
1. That the
values returned from the data source are numeric. It may be stating the
obvious but you cannot total values that are not numeric. Numbers
formatted with currency symbols should be OK.
2. The list
of values is in a table cell.
When both
conditions are met, you can add an Expression (=) field to a final row
of the table. This field can be
formatted using switches as required. |
|


|
| Running the Merge |
|
|
Having
setup the merge document and data source, the next
step is to run the macro.
The macro is designed to work in conjunction
with Outlook as the default email application. Where Outlook is not
available, the options to merge to e-mail will not be offered and the
merge may only be made to separate documents or PDF files. |
|
|
If the data
source is detached or is of the wrong type of file, or if the merge
document type is not 'Letters', the user will be presented with a warning message
that explains the error i.e. |
|
 
  |
|
|
If all is
well the macro presents a userform, from which the key field and the
repeating fields are selected. However on first use, a disclaimer screen
is show. This will be shown each time the application is run until you
select the option not to display it. Thereafter it may be selected from
the tabs along the top of the dialog box. There is also a help screen
shown in the second illustration below. |
|
 
 
 
 
  |
|
Saved documents |
|
|
The
documents created as attachments are first saved to the hard drive. You
will be prompted to choose a location to save the documents. |
|

|
|
Messages merged to e-mail |
|
|
The e-mail
options provide the ability to select both a signature and the sending
account, should you have more than one account. You may also enter a
suitable subject line and a covering message.
When
'Continue' is clicked, the messages are sent to a temporary sub folder
of the Outlook drafts folder (to ensure a unique location). You will
have the choice of removing the temporary folder later when you send the
messages. The function looks for the presence of the folder and if it is
not present will create it. There is an additional button on the ribbon
that provides a function to remove the temporary folder should you
change your mind about retaining it. When removed the temporary folder
is removed completely. It is not merely moved to the Deleted items
folder.
The temporary folder allows the safe examination of the
messages and attached documents produced, before committing to sending
them. They will only be sent when the 'Send Messages' button is clicked.
If you have
Outlook configured to send messages immediately when connected (see
below), clicking the 'Send Messages' button, irretrievably sends the
messages to their destination e-mail addresses. If you have the option
set not to send messages immediately when connected, then you have a
further opportunity to change your mind. However if you choose not to
send at the prompt, then you must use the Outlook Send and Receive
function to send on the messages. The button on the Word Mailings ribbon
only sends messages that are in the temporary folder.
Where Outlook is not present, the Outlook functions are omitted and
'Continue' merely sends separate documents to the selected Windows
folder. |
|
Note: |
The option to merge to the body of an
e-mail message, which appeared in some earlier versions of the add-in,
has been removed.
I am ambivalent about whether this option
should be included. My principal objection is that the Word document
format is not retained by the message format, so the results can be a
travesty of the original document. I may be persuaded to restore this
option if there is sufficient demand, but if you wish to retain your
merge document format, you would be better attaching the document,
preferably in PDF format. |
| Invalid e-mail
addresses |
|
|
It is essential that the e-mail addresses in the data
source are both present and valid when an option to merge to e-mail is
selected. When such an option is selected, the add-in will examine all
the e-mail addresses in the record set and if any addresses do not meet
the required standards for e-mail address formats, the process will be
stopped and you will see a warning message and the erroneous record
numbers and associated e-mail addresses are listed in a new document to
help you locate and correct them. Note that it is the record number
shown and not the row number in the Excel worksheet.
This
function caters for the vast majority of possible e-mail address
configurations, however should you discover a genuine e-mail address
reported as erroneous, or an erroneous address that is not flagged as
incorrect then please e-mail me with the details so that I may
modify the error trapping. |
|
  

|
|

|
 |
| |
At various
times you may see one of the following information messages: |
|
 
 
 
|
| |
|
| |
- Now
download the add-in |
|