Graham Mayor

... helping to ease the lives of Microsoft Word users.

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 would help to ensure the continued availability of this resource. Click the appropriate button above to access PayPal.

Hyperlink Mergefield Add-in for Word 2007 and later

Variable hyperlinks chosen from a mail merge data file are complicated to create especially if the hyperlink display text is also variable, or a the hyperlink is attached to merged graphics. This Word add-in aims to overcome that.

The add-in will not insert hyperlink fields in text boxes or in the header/footer ranges of the merge document. This is quite simply because hyperlinks in such locations do not work in Document format as the ranges themselves must first be selected to make the link accessible.

If the merge is intended to be split to separate files in PDF format, using the Many to One add-in, then it is permissible to use links in text boxes; so where this is a requirement, insert the link into the body of the document (or into another blank document attached to the same data source) and then drag the link to the required location.

The add-in puts a pair of buttons on the Mailings Tab of the Ribbon:

The first button runs the process, the second operates a drop-down menu with three commands.

  • The first is a new addition to process documents that have already been merged to split such a document to the bodies of e-mailed messages and is documented at the end of this page.
  • The second is used to process documents that have already been merged and is explained later on the page.
  • The third is used following a merge to a new document. Unfortunately the merge fields do not update when merged (except when merged using the Many to One or the Merge and Split add-ins) and so it is necessary to merge to a new document and use this button to update the fields in that document to reflect the correct data.
  • The last is used to reset the variables stored in the template.

The Update All Fields function is not limited to use with this add-in. It will update all fields in a document generally.

When activated the process determines that the document is a merge document and that a data source is attached. This is essential as the function will use that data source to apply the field structure to the document.

The dialog is self explanatory. Clicking the first check box alters the dialog to provide options for using a graphic as a hyperlink:

When graphics are used as links, the data source should not contain the path to the graphics files. It should contain only the filename, with or without the extension as shown below. The path is user selected as part of the process. Links must be in valid link format.

Using the above data source as an example (a Word table) the four pictures refer to four rectangular coloured blocks, however in a real world situation you can use any practical graphics:


Depending on the options chosen you would see either the link, the display text or the image inserted into the document.

Because of the complexity of inserting the links into tables, including labels, I have trapped such insertions and a message (below) advises how to proceed. The use of a temporary merge document will inevitably be required when using the links in conjunction with a merge to mailing labels. (See also Graphics on Labels).

The final illustrations show how a graphic link has been inserted into a table cell used in a directory merge.


Replace Display Texts with Hyperlinks

The add-in includes a second major function, the first item in the drop down section of the Ribbon group. The purpose of this function is to replace display texts in a document, with hyperlinks that relate to those display texts, from an Excel data file that includes the display text, the URL to be linked to and optionally a screen tip text.

The document being processed could be the result of a mail merge or a document that has a variety of texts that need to be hyperlinked. It cannot be a merge document.

Only Excel data files may be used with this function, to list the texts to be found and the hyperlinks (and screen tip texts if used) that relate to those texts.

The datasheet need not be the data source used for the original merge.

Where the data source used for the original merge contains the hyperlink data, the main function described at the start of this page could be used instead.

Note: If the texts to be hyperlinked are already the URLs to be linked to, Word's built-in autoformat function should be used to convert such texts to hyperlinks. The Replace Texts with Hyperlinks function is used with texts that are NOT the URLs to be linked to.

This part of the add-in evolved separately, but as it is so closely related to the mail merge function and shares several code modules, I decided to include it from Version 2 in the same add-in as the mail merge function.

The function has a separate but similar userform as shown below.

The example shown below is a simple directory merge document. It features a simple description and a code that relates to the description. When merged to a new document, you get a list of the merged items and their codes (I have only shown the beginning of the list).

The function can be used to replace the codes (or the descriptions, or - in two operations - both) with hyperlinks to the web pages etc. that relate to those codes or descriptions.


Merge to the bodies of e-mail messages

This process, a more recent addition, was prompted by a user who reported that the hyperlink merge link text did not survive being merged to the bodies of e-mailed documents. To overcome this I came up with an option to merge a document that had been merged, and which included hyperlink merge fields created with this add-in, to the bodies of e-mailed messages.

To use the process, ensure that the merge document has the e-mail address field at the end of the document followed by a paragraph break. This is used to address the individual messages

Merge the document to a new document ( Mailings Tab > Finish and Merge > Edit Individual Documents)

Then run the process from the add-in's Menu.

After checking to ensure that the merged document is valid for the process, the following dialog is displayed:

The check box has been added to allow the user to check that merge works as intended by merging and displaying only the first three records. This is the default setting.

If the check box is checked (see below), ALL the messages in the set are sent directly to the outbox of Outlook. If Outlook is configured to send messages immediately, the messages are sent!

- Click here to download the add-in




This add-in was originally developed to help overcome the difficulty of using merged hyperlinks with variable display texts.