Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2017, 09:34 PM
myUserNamez myUserNamez is offline Converting html link to ms word link Windows 7 64bit Converting html link to ms word link Office 2010 64bit
Novice
Converting html link to ms word link
 
Join Date: Jan 2017
Posts: 2
myUserNamez is on a distinguished road
Default Converting html link to ms word link


I consistently receive word documents that are littered with html links like <a href="http://example.com"> click me </a> is there a way using vba to convert this to a proper link in word, so it looks like, and acts like a standard link (i.e.) click me.
Reply With Quote
  #2  
Old 01-04-2017, 10:22 PM
gmayor's Avatar
gmayor gmayor is offline Converting html link to ms word link Windows 10 Converting html link to ms word link Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You could do this with a macro e.g.

Code:
Sub ReplaceHTMLLinks()
Dim oRng As Range
Dim sLink As String
Dim sAddr As String
Dim sDisplay As String
Dim vLink As Variant
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(FindText:="\<a href=*\<\/a\>", MatchWildcards:=True)
            sLink = oRng.Text
            vLink = Split(sLink, Chr(34))
            sAddr = vLink(1)
            sDisplay = Replace(Mid(sLink, InStr(1, sLink, ">") + 2), " </a>", "")
            oRng.Text = ""
            oRng.Hyperlinks.Add Anchor:=oRng, _
                                Address:=sAddr, _
                                TextToDisplay:=sDisplay
            oRng.Collapse 0
        Loop
    End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-04-2017, 10:47 PM
myUserNamez myUserNamez is offline Converting html link to ms word link Windows 7 64bit Converting html link to ms word link Office 2010 64bit
Novice
Converting html link to ms word link
 
Join Date: Jan 2017
Posts: 2
myUserNamez is on a distinguished road
Smile Thanks

Thanks for the prompt reply, the code you supplied works a treat.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to trigger a html link using rules. kitcha321 Outlook 1 06-15-2015 09:17 PM
Converting html link to ms word link An html link from Excel works, but now there is too much extra space in the cell njweatherdon Word 2 09-22-2014 09:06 PM
Trying to link page numbers in the footer, but refuses to link after new section fl0shizzle Word 7 05-06-2014 12:15 PM
How to link an object to a URL link to update automatically expert4knowledge Excel 1 06-11-2012 09:30 AM
Converting html link to ms word link Outlook macro for automatically converting plain text to link? nrogers64 Outlook 1 09-17-2010 01:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft