![]() |
|
#1
|
|||
|
|||
|
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.
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
Thanks for the prompt reply, the code you supplied works a treat.
|
|
|
|
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 |
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 |
Outlook macro for automatically converting plain text to link?
|
nrogers64 | Outlook | 1 | 09-17-2010 01:35 AM |