Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Mail Merge

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-19-2017, 02:57 PM
jeffreybrown jeffreybrown is offline Windows Vista Office 2007
Expert
 
Join Date: Apr 2016
Posts: 333
jeffreybrown is on a distinguished road
Default Creating Hyperlinks after a Mail Merge

After running the mail merge, I use the code below to turn e-mail addressed into hyperlinks, but the text gets indented.



Code:
Sub MakeLinks()
    Application.ScreenUpdating = False
    Dim Rng As Range
    With ActiveDocument
        Set Rng = .Range
        With .Range
            With .Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .text = "<[0-9A-.\-]{1,}\@[0-9A-\-.]{1,}"
                .Replacement.text = ""
                .Forward = True
                .Wrap = wdFindStop
                .Format = False
                .MatchWildcards = True
                .Execute
            End With
            Do While .Find.Found
                .Duplicate.AutoFormat
                .Collapse wdCollapseEnd
                .Find.Execute
            Loop
            .End = Rng.Start
            With .Find
                .text = "http://[! ]{1,}"
                .Execute
            End With
            Do While .Find.Found
                .Duplicate.AutoFormat
                .Collapse wdCollapseEnd
                .Find.Execute
            Loop
        End With
    End With
    Application.ScreenUpdating = True
End Sub
Without creating a table for each mail merge field, can this be overcome? In the mail merge template, the e-mail is preceded by a phone number, which is this case is blank. I have tab stops setup in the mail merge template to space out the phone number followed by the e-mail.
Attached Images
File Type: gif Capture.GIF (3.2 KB, 6 views)
Reply With Quote
  #2  
Old 09-19-2017, 04:15 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,341
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

You don't need a macro for this! See Mailmerge Hyperlink ‘Click Here’ Insertion in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum:
http://www.msofficeforums.com/mail-m...ps-tricks.html
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 09-19-2017, 06:14 PM
jeffreybrown jeffreybrown is offline Windows Vista Office 2007
Expert
 
Join Date: Apr 2016
Posts: 333
jeffreybrown is on a distinguished road
Default

Thanks Paul...Got it now, however, it seems right after the merge to a new document, I go back to the template and the field is no longer a hyperlink.

If I create the hyperlink in the template and perform the merge, all works good, but again, after the merge or when selecting save before the merge I lose the hyperlink.

Does this sound like what you've experienced before?

Last edited by jeffreybrown; 09-19-2017 at 06:20 PM. Reason: Update wording
Reply With Quote
  #4  
Old 09-19-2017, 06:32 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,341
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Hyperlink fields can be finicky that way. Simply save mailmerge main document before doing the merge but don't re-save it afterwards. If you need to make changes to the mailmerge main document, don't make/save them after doing a merge; make/save them beforehand.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 09-19-2017, 06:35 PM
jeffreybrown jeffreybrown is offline Windows Vista Office 2007
Expert
 
Join Date: Apr 2016
Posts: 333
jeffreybrown is on a distinguished road
Default

Okay thanks. For awhile there it was driving me nuts. Couldn't see what I was doing wrong.
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlinks in IF...THEN Mail Merge ljg713 Mail Merge 18 12-16-2015 11:35 PM
Creating recipient list for mail-merge Roger Keeling Mail Merge 2 05-23-2015 04:34 AM
Creating new documents from a mail merge template pnjcarter Mail Merge 1 02-03-2014 06:42 PM
Mail merge from Excel to Word and include hyperlinks chay Mail Merge 5 09-28-2013 01:16 AM
Need help creating a data base for mail merge. acedking90 Mail Merge 0 07-27-2009 11:04 AM


All times are GMT -7. The time now is 02:06 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft