0

I am trying to create a mail merge with a hyperlink inside of an “if” statement (the link only appears if a certain mergefield exists), where both the link address and display text are different mergefields. I am using Microsoft Word, Version 16.101.3.

I have gotten the mergefield links to work outside of the “if” statement doing the following:

  1. Insert > Field > Hyperlink; this creates the following: { HYPERLINK \* MERGEFORMAT }

  2. Insert a mergefield into the code: { HYPERLINK { MERGEFIELD personal_link } \* MERGEFORMAT }

  3. The default text says “Error! Hyperlink reference not valid.” I replace this text with a mergefield { MERGEFIELD personal_text } and delete the other text

However, these steps do NOT seem to work inside of an “if” statement. I can still do steps 1 and 2 above, but then the text itself is not clickable, and if I try to add a mergefield within the display text it just disappears.

Is this a bug, or am I doing something wrong? Are there any workarounds?

If it is not possible to get personalized display text, I would be okay with just generic text as long as the link address is a mergefield. But right now I cannot get either to work! Any help would be greatly appreciated.

Thank you!

1 Answer 1

1

You can't embed hyperlink fields inside IF fields in a mailmerge and get a working hyperlink field at the end. You would need to use a post-merge macro to convert them into hyperlinks - in which case you might as well just have {MERGEFIELD personal_link} inside your IF test. See the Activate Plain-Text Email Addresses & Hyperlinks topic on the Mailmerge Tips & Tricks page at: https://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html.

You can also use IF fields inside hyperlink fields to vary the hyperlink address and/or the hyperlink display text. For basic instructions on how to vary the hyperlink display text, see the Mailmerge Hyperlink ‘Click Here’ Insertion topic on the Mailmerge Tips & Tricks page at: https://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html In this case, you could use a post-merge macro to delete any invalid hyperlinks.

The “Error! Hyperlink reference not valid.” message is to be expected before the merge is executed, as {MERGEFIELD personal_link} is not itself a valid hyperlink address. You can probably delete the * MERGEFORMAT switch; it likely does nothing useful in the context.

Sign up to request clarification or add additional context in comments.

1 Comment

The page you linked was very helpful -- I ended up using (a slightly modified version of) the code to post-process url text and display text to create a clickable link in my final document as needed. Thanks so much for the help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.