Customize filenames of individual images (hosted on my website) onper-recipient basis using mail mer

S

Shawn Syms

Greetings, all! I'd like to use the Word/Outlook mail merge
functionality to send personalized email to person1, person2 and
person3. Easy enough. But in addition to wanting to address them as
"Dear person1," etc, I would also like each email message to include
an HTML reference to an individualized image on my website that is
distinct for each recipient:

<img src="http://www.mysite.com/images/image_person1.gif"> in the
first message
<img src="http://www.mysite.com/images/image_person2.gif"> in the
second message
<img src="http://www.mysite.com/images/image_person3.gif"> in the
third message

and so on.

Is this possible/relatively easy for a non-programmer to achieve? I've
searched this group and don't believe I've found the answer yet. I see
instructions on how to include references to such images in general,
but no cases where the filename itself is created as part of the mail
merge process.

Thanks for any assistance! Best regards,
Shawn
 
P

Peter Jamieson

How to do this depends partly on your version of Word/Outlook, but the
following is what I believe to be necessary with Office 2003 and 2007,
and which seems to work here.

The overview:
a. Your mail merge data source must contain the URL of the picture you
want to include
b. you have to use a particular combination of Word fields to insert
the picture.
c. you have to make a setting in Outlook so that it sends a link to an
http URL rather than a link to a copy of the picture in the email. In
Outlook 2007, you have to modify the Windows registry to do that.
d. You have to use VBA to update the pictures for each email
e. your recipients also have to be using email client software and
settings that behave the way you expect :)

Alternatively, you may be able to use third party software to do it, but
I cannot recommend any particular package.

Let's work through this stuff

(a) Picture URLs

Obviously, you have to get your picture URLs from somewhere. If you have
a field in your data source with the complete URL of the picture, you
can just use that field. Let's suppose you have a field call PictureURL
that contains exactly that. Or maybe the folder name is the same for all
the images and you just have the file name part (image_person1.gif) in
each record. Let's suppose you have a field called PictureFilename that
contains that)

(b) Fields to insert the picture

The following combination of fields seems to be sufficient to to the job
(At this point I am pretty sure that the QUOTE and INCLUDEPICTURE are
essential but I am not so sure about the \d)

{ QUOTE { INCLUDEPICTURE "{ MERGEFIELD PictureURL }" \d }

or e.g.

{ QUOTE { INCLUDEPICTURE "http://www.mysite.com/images/{ MERGEFIELD
PictureFilename }" \d }

I suggest you insert these fields manually, especially in Word 2007,
otherwise you may find that the INCLUDEPICTURE is replaced by its
result. Each of the pairs of {} has to be the special field braces you
can insert using ctrl-F9, not the ordinary ones on the keyboard.

You need to update these fields once before you merge.

When you save your file and re-open it, make sure that the
INCLUDEPICTURE has not been replaced by its result. I think that may
occur when Word 2003's Tools->Options->General->Web
options->Files->"Update links on save", or the Word 2007 equivalent at
Word office button->Word options->Advanced->Web options->Files->"Update
links on save" is checked and you may find you need to uncheck it.

You need the INCLUDEPICTURE because otherwise Word does not know that it
is supposed to be including a picture. You need the QUOTE because
otherwise Outlook sends the image inline, i.e. not as a link.

(c) Outlook settings.

Not many settings in Outlook obviously affect the format of your emails
when merging from Word, but to get links instead of inline images, if
you are using Outlook 2003, you have to uncheck
Outlook|Tools|Options|"Mail Format"|"Internet
Format"|"When an HTML message contains pictures..."

In Outlook 2007, this option is no longer available in the UI. It has
presumably gone out of fashion because people think it is more secure to
open an inline image than visit a link at a URL. But you can set the
option in the Windows registry. Look for a key called

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Options\Mail

(I had to create the Mail key under the options Key here, but that's
probably because I don't use Outlook much on this system)

Under that key, look for or create a DWORD value called

Send Pictures With Document

Then set its value to 0.

() VBA code

Word does not automatically update INCLUDEPICTURE fields when you merge,
except in the special case where you are merging directly to the
printer, you have Print options->Update links checked, and you use the
\d option in the field. More or less. So this is why you have to have
some kind of code that updates the field. For various reasons, I'd argue
that the simplest way to do this in Word on Windows is to use VBA and
Word Events, although there are other options.

To do that, you need to do the following:

1. Create a new document, connect it to your data source, and insert the
nested QUOTE field as above

2. Open up the VBA Editor and
a. insert a class module.
b. name it EventClassModule in the properties box
c. Copy the following code into the module:

Public WithEvents App As Word.Application

Private Sub App_MailMergeBeforeRecordMerge(BYVal Doc As Document, Cancel
As Boolean)
Dim objField As Word.Field
For Each objField In Doc.Fields
If objField.Type = WdFieldType.wdFieldIncludePicture Then
objField.Update
End If
Next
End Sub

3. Insert an ordinary module (the name does not matter) and insert the
following code:

Dim x As New EventClassModule

Sub autoopen()
Set x.App = Word.Application
End Sub

4. Save and close the document. Open it to trigger the autoopen, then
perform a test merge.

Simple, huh? :)) All I can say is that it works here. However, the last
time I had a similar conversation on this subject, the other guy's copy
of Office was inserting HTML that looked like

<img url="cid:http://etc"

i.e. was still trying to reference another MIME part within the message,
and getting it wrong, rather than what was needed, i.e.

<img url="http://etc"

We never got to the bottom of that...

Peter Jamieson

http://tips.pjmsn.me.uk
 
S

Shawn Syms

Thanks so much for your effort and suggestions, Peter! Your
recommendations are really nudging the borderlines of what I am
capable of, but I think I am going to give it a try! Much obliged.

Cheers,
S.
 

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