As far as I know, the only way to change the target URL for each message is
to use VBA, and since you're merging to e-mail, the only ways to do that are
a. use VBA and Word Events to insert the hyperlink you need for each
e-mail. This is tricky (worse than "Normal" VBA).
b. (theoretically) merge each record to a new document, then fix the
hyperlink using VBA, then use Doug Robbins' merge to e-mail with attachments
approach, as per
http://word.mvps.org/FAQs/MailMerge/MergeWithAttachments.htm
but that is probably even trickier overall.
For option (a), the fllowing approach used to work for ordinary merges but I
haven't tried it recently.
1. Create a new document, connect it to your data source, and insert one
merge field and a bookmark named "mybm"
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 dt as String
Dim lt as String
Dim h as Hyperlink
Dim r as Range
' set the range variable to our placeholder bookmark
Set r = Doc.Bookmarks("mybm").Range
' delete any existing text (this is needed for records after record 1)
r.Text = ""
' construct the link text that you want. I'm assuming your data source has
fields called idfield and namefield.
lt =
http://www.testsite.com?id= & _
Doc.MailMerge.DataSource.DataFields("idfield") & _
"&name=" & _
Doc.MailMerge.DataSource.DataFields("namefield")
' set up the display text that you want. If it should be the same as the
link text, do that:
dt = lt
' insert the hyperlink you want
Set h = Doc.Hyperlinks.Add(Anchor:=r, Address=lt, TextToDisplay:=dt)
' Set mybm to "cover" the inserted link so it is easy to delete the old
hyperlink
Doc.Bookmarks.Add Name:="mybm", Range:=h.Range
Set r = Nothing
Set h = Nothing
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.
NB, if you start changing the code you may find that you need to re-run your
autoopen code again, and/or save/close/open the document.
Peter Jamieson