Solved

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

Posted on 2014-12-26
2
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

630 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