问题
I'm trying to add a hyperlink to a mail merge field. So something like this:
{HYPERLINK "{MERGEFIELD "Links" }"}
So I create a field like this.
{ MERGEFIELD Links }
And the above works (it displays different links for different recipients).
However, when I go to Edit Field, and then attempt to add HYPERLINK to { MERGEFIELD Links}, Word will not allow me. Meaning that when I type HYPERLINK followed by a space, the "variable" field is gone. Instead of word displaying...
LINK
it displays...
{HYPERLINK "{MERGEFIELD "Links" }"}
even after I press "update field". So Word is not letting me enter HYPERLINK for some reason.
How do I solve this?
回答1:
From the Microsoft Web Site,
- On the
Insert
menu, clickField
(under Quick Parts in later office versions). - In the Field names list, click Hyperlink,
and then click 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. - On the Insert menu, click
Field
. In theField names
list, clickMergeField
. In the Field name text box, type the name of the data source field that contains the hyperlink, and then click 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 field code. You now have
Error! Hyperlink reference not valid
text. - Put the insertion point at some arbitrary place in the middle of the
Error! Hyperlink reference not valid
text, and insert the text you want to appear. If you would like a merge field, insert that from the "Insert Merge Field" option on the menu. - Delete the remaining text of
Error!
... before and after the text you want to keep.
Note: If your merge field only contains an identifier, with the URL to be provided as a static part of the merge document, this can work also. On Step 5, you will need to insert the URL text as well as the MergeField, for example:
{ HYPERLINK "https://www.myurl.com/EditForm.aspx?ID={ MERGEFIELD ID }" \* MERGEFORMAT }
回答2:
I also have been struggling with this. What I found to be the key is creating the document from SCRATCH and not saving it before executing the mail merge. Here are the steps I used:
- open a new document and click on the step by step mail merge wizard; add your generic text.
- To add the variable hyperlink go to insert>quick parts>fields
- select hyperlink on the left and click okay
- Use alt + F9 to see the hyperlink field code
- Type
“”
and between them insert your merged field so that{HYPERLINK \* MERGEFORMAT}
-> becomes{HYPERLINK"{MERGEFIELD"Constructed_URL"}"\*MERGEFORMAT}
- Press ALT+F9 to hide the field code
- Click in the text "Error! Hyperlink reference not valid" and replace with something generic like click here.
- Complete the mail merge BEFORE you save the document.
Hope this helps and good luck!
回答3:
Start with the process here: http://support.microsoft.com/kb/912679 However, like user1867326 indicated, the hyperlink (which should be variable with the mail merge) is converted into a static link when the Word file is reopened.
A solution that seems to work is adding a bookmark within the hyperlink field code immediatly after the mergefield.
{ HYPERLINK { MERGEFIELD "Link" } \* MERGEFORMAT }
Click between the } and \ and go to INSERT > Bookmark, give it a name, and this seems to prevent Word from replacing the mergefield with a static hyperlink.
This answer is adapted and hopefully clarified from the clever solution described here: Mailmerge dynamic hyperlink fields lost after save/reload of document - Word 2010
回答4:
This is what worked for me for an email mail merge with variable hyperlinks that all display the same text. I am using Office 2016 Word.
- Put the insertion point where you would like the link display text to be in the document.
- On the Insert menu, click Quick Parts, and select Field.
- In the Field Names list, click Hyperlink, and then click OK. The text Error! Hyperlink reference not valid appears in the document.
- Press ALT+F9 to open the { HYPERLINK * MERGEFORMAT } field code. 5. Put the insertion point after HYPERLINK.
- On the Insert menu, click Quick Parts, and select Field. In the Field Names list, click MergeField.
- In the Field name text box, type the name of the data source field that contains the hyperlink, and then click 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 field code. You now have Error! Hyperlink reference not valid text.
- Put the insertion point just before the period in ‘Error! Hyperlink reference not valid text.’ and delete all the text except for the period. Write in the link display text. Make sure not to delete the period (this is important).
- To check that the hyperlinks are mapping, right click on the link display text and click edit hyperlink. You will see the correct link in the address field for each record.
- I like to style the period text color to white so it looks invisible.
回答5:
I have had limited success with the other suggestions - basically, Word is buggy in this area. There is a simple alternative - indeed the only alternative AKAIK if you want the hyperlink to vary AND the text that is displayed to vary too (not an unreasonable requirement).
Note that this only works for DOCUMENT MERGES, not for EMAIL MERGES, since it relies on processesing the output document.
The trick is to add a place marker (text that serves as an ID) wherever you want a hyperlink. Insert this via a regular mergefield. In your table of source data, you need columns
place marker, text_for_display, hyperlink
You then need to put your source data into Excel (if that isn't where you have it already) and put this formula
="Set Rng = ActiveDocument.Content: Rng.Find.Execute FindText:="""&[place marker]&""": ActiveDocument.Hyperlinks.Add Anchor:=Rng, Address:="""&[hyperlink]&""", TextToDisplay:="""&[text_for_display]&""""
into a blank column in the first row, and fill down.
You need to amend [place marker],[hyperlink] and [text_for_display] to the appropriate cell references.
If the [hyperlink] includes a query string, you may find you want to build it using a formula, based on other data in the source.
The resulting formulae can then be pasted into a macro and run on the output document.
You may then want to use the "Robbins/Mayor" macro http://www.wordbanter.com/showthread.php?t=18346 to split the generated documents.
来源:https://stackoverflow.com/questions/17428891/add-variable-hyperlink-in-mail-merge-in-word-2013