Another possibility is to use mail merge events and vba to insert the
HYPERLINK fields you need. Here's something I've posted before - probably
needs testing and adaptation but may be worth a try.
As far as I know:
a. as a general rule, you cannot guarantee that HTML features will work as
you hope because the recipient's email client may not be configured to
display them (or may not be able to do so). But...
b. you have to use a { HYPERLINK } field in Word
c. a link has two parts: a display text, which is what the user actually
sees in the message they receive, and a link text, which is the target that
will be opened if the user clicks the link.
d. as long as your link is fixed and you have inserted it with the correct
display text and link text, and Word has recognised it and turned it into a
{ HYPERLINK } field, the link should be preserved
e. if you are trying to insert hyperlinks "on the fly", e.g. getting the
link text from a field in your merge data source, the problem is that
although the link text may be updated if you insert the link correctly, the
display text is never changed after the { HYPERLINK } field has been
created. You can only change the display text programmatically.
f. so the only way I know to get around this when merging to e-mail is to
use the Word MailMerge events to insert a completely new Hyperlink field for
each record in the data source.
If you want to go that route, you need to look up Word Events from the Help
function in the VBA editor, but for example, if your data source has a
column "displaytext" containing the display text you want, and "linktext"
containing the link text you want, if you insert a Word bookmark at the
point where you want the link and use the following code in the
MailMergeBeforeRecordMerge event you may get what you want:
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.
lt = Doc.MailMerge.DataSource.DataFields("linktext")
' set up the display text that you want.
dt = Doc.MailMerge.DataSource.DataFields("displaytext")
'Or 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 next time
Doc.Bookmarks.Add Name:="mybm", Range:=h.Range
Set r = Nothing
Set h = Nothing
End Sub
Peter Jamieson
> Cindy;
>
[quoted text clipped - 32 lines]
>> follow question or reply in the newsgroup and not by e-mail
>> :-)
Gary N - 19 Jan 2006 18:07 GMT
Hi Peter,
This code works great!
Is there a way it could be modified so that a image can be used as a merged
hyperlink as well?
Thanks a bunch!
>Another possibility is to use mail merge events and vba to insert the
>HYPERLINK fields you need. Here's something I've posted before - probably
[quoted text clipped - 70 lines]
>>> follow question or reply in the newsgroup and not by e-mail
>>> :-)
Gary N - 19 Jan 2006 20:47 GMT
Hi Peter,
Nevermind, I got the code to work for images as well :-)
Thanks again
>Hi Peter,
>
[quoted text clipped - 10 lines]
>>>> follow question or reply in the newsgroup and not by e-mail
>>>> :-)