Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-12-26
2
Medium Priority
?
581 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

705 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