When you perform a mail merge to e-mail messages in HTML format in Microsoft Word, the hyperlinks in data source fields appear as plain text and are inactive. This article describes two methods to work around this problem.
Method 1: Add a hyperlink field around the mail merge field
Add a hyperlink field around the mail merge field to generate a hyperlink in the merged e-mail messages. After you follow these steps, the hyperlink displays the same text in all the e-mail messages. Additionally, the hyperlink connects to the correct data source URL.
To do this, follow these steps:
-
Start Word and open the document that you want to merge to e-mail.
-
On the Mailings tab of the Ribbon select Start Mail Merge. Select Step-by-Step Mail Merge Wizard... and the Mail Merge Wizard appears on right hand side.
-
Under Select document type, select E-mail messages, and then select Next.
-
Under Select the starting document, select Use the current document, and then select Next.
-
Under Select recipients, select the recipients that you want to use, and then select Next.
-
Put the insertion point where you want the hyperlink to appear in the e-mail message.
-
From the Quick Parts menu in the Text section of the Insert Ribbon tab, select Field.
-
In the Field names list, select Hyperlink, and then select OK. The text "Error! Hyperlink reference not valid" appears in the document.
-
Press ALT+F9 to open the { HYPERLINK \* MERGEFORMAT } field code.
-
Put the insertion point after HYPERLINK and then add a space.
-
From the Quick Parts menu in the Text section of the Insert Ribbon tab, select Insert Merge Field.
-
In the Field names list, select MergeField.
-
In the Field name text box, type the name of the data source field that contains the hyperlink, and then select OK. For example, if the name of the data source field is "Address1," the field code appears as follows:
{ HYPERLINK { MERGEFIELD "Address1" } \* MERGEFORMAT }
-
Press ALT+F9 to close the { HYPERLINK { MERGEFIELD "<Field Name>" } \* MERGEFORMAT } field code.
-
Put the insertion point at the start of the "Error! Hyperlink reference not valid" text, and overwrite the text with the hyperlink text that you want to appear. For example, overwrite the text with text such as CLICK HERE.
Important: Make sure that you don't delete the whole field.
-
Select the text that you typed in step 15. Select on the lower right disclosure button on the Styles section of the Home tab of the ribbon, and then select Hyperlink.
-
In the Mail Merge Wizard, select Next, and then follow the remaining steps in the Mail Merge Wizard to complete the mail merge process.
Method 2: Create a macro that dynamically modifies the hyperlink text
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures.
Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Create a macro if you want to dynamically modify the hyperlink text in your merged e-mail messages.
After you follow these steps, the hyperlink displays text that is based on the URL in the data source. To do this, follow these steps:
-
Follow the steps in "Method 1: Add a hyperlink field around the mail merge field."
-
On the Tools menu, point to Macro, and then select Visual Basic Editor.
-
Press F7. The code window appears.
-
Copy and paste the following code into the code window:
Sub MergeToEmail() Dim bDone As Boolean bDone = False Do While bDone = False ActiveDocument.Fields.Update For Each oHyperlink In ActiveDocument.Hyperlinks oHyperlink.TextToDisplay = oHyperlink.Address oHyperlink.Range.Font.Color = wdColorBlue oHyperlink.Range.Font.Underline = wdUnderlineSingle oHyperlink.Range.Font.UnderlineColor = wdColorBlue Next oHyperlink With ActiveDocument.MailMerge .Destination = wdSendToEmail .SuppressBlankLines = True ' You can modify the text "Enter Your Subject Here" or ' remove the following line if you do not want a subject ActiveDocument.MailMerge.MailSubject = "Enter Your Subject Here" With .DataSource .FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord .LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord End With .Execute Pause:=False End With If ActiveDocument.MailMerge.DataSource.ActiveRecord = _ ActiveDocument.MailMerge.DataSource.RecordCount Then bDone = True End If ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord Loop End Sub
-
On the Tools menu, point to Macro, and then select Macros.
-
Select MergeToEmail, and then select Run.
Note: For each e-mail message that you send by using this macro, a warning message from Microsoft Outlook appears.
Warning: Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
More Information
For more information about how to use the mail merge functionality to create e-mail messages, go to: How to use mail merge to create e-mail messages in Word 2002.
For more information about how to obtain help with Visual Basic for Applications, go to:
305326 List of programming resources for Visual Basic for Applications