Solved

Insert an active but variable hyperlink from the DataSource in a MailMerge Word doc

Posted on 2014-12-26
2
443 Views
Last Modified: 2015-01-12
Hello,

How do you insert an active but variable hyperlink from the DataSource in a mail merge Word (2013) document?

For example, suppose you are doing a Word mail merge and have defined, as you're DataSource, an Excel file (named Source.xlsm) which contains several hundred records (rows). Also, suppose that the 6th column in the Excel file has the heading URL and contains several dozen different URLs distributed randomly throughout the records.

When the mail merge Word doc is created, the URL for a given record appears wherever the <<URL>> field is placed. However, it appears as simple text just like the rest of the document and does not have any hyperlink functionality.

Questions:

1) In a Word mailmerge, how do you create a <<URL>> field which has hyperlink functionality?

2) Is there a way to display a "friendly name" (using the term from the Excel =HYPERLINK() function) as the hyperlink in a mailmerge rather than the URL itself? (For this question, assume that the 5th column [in the Excel file used in the above example] has the heading "URL Name" and contains the "friendly names" for each record.)

Thanks
0
Comment
Question by:WeThotUWasAToad
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40519537
There isn't a method for that built-in to MailMerge, but it can be done with VBA code. This Word macro example finds the worksheet and copies the cell with the hyperlink (here from column 3) into a place where there is a some distinctive text (here "@@@@")
Sub StepMerge()
    Dim r As Integer
    Dim rng As Word.Range
    Dim xlApp As Excel.Application
    Dim xlWbk As Excel.Workbook
    Dim xlWks As Excel.Worksheet
    Dim wdMainDoc As Document
    Dim wdResultDoc As Document
    Dim strQueryParts() As String
    
    Set wdMainDoc = ActiveDocument
    Set xlApp = CreateObject("Excel.Application")
    Set xlWbk = xlApp.Workbooks.Open(wdMainDoc.MailMerge.DataSource.Name)
    strQueryParts = Split(wdMainDoc.MailMerge.DataSource.QueryString, "`")
    Set xlWks = xlWbk.Worksheets(Replace(strQueryParts(1), "$", ""))
    
    With wdMainDoc.MailMerge
        .Destination = wdSendToNewDocument
        For r = 1 To .DataSource.RecordCount
            .DataSource.LastRecord = r
            .DataSource.FirstRecord = r
            .Execute
            Set wdResultDoc = Application.ActiveDocument
            Set rng = wdResultDoc.Range
            With rng.Find
                .Text = "@@@@"
                .Execute
                xlWks.Cells(r + 1, 3).Copy
                rng.Paste
            End With
        Next r
    End With
    xlWbk.Close False
    xlApp.Quit
End Sub

Open in new window

0
 

Author Closing Comment

by:WeThotUWasAToad
ID: 40545755
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now