Productivity Tips

Word Macro to Convert Word Hyperlinks to HTML Hyperlinks

This Word macro converts Word hyperlinks to HTML link format. It comes in handy if you need to get a Word document onto a website and your Word doc includes links in the Word hyperlink format.

Here's a simple Word macro we use to convert Word hyperlinks into HTML hyperlinks.

If the link is to a page on our site, we get rid of the "" part of the link since that is not necessary. In addition, if it's an internal link to a page on our site, we don't add any Target= or Rel= attribute. On the other hand, if it's an external link, we automatically add in Target = "_blank" and Rel="nofollow" to the HTML a href tag.

Hope this code comes in handy for others. It has saved us from having to manually convert Word links to HTML code.

Sub AddHREF()
' Turn Word hyperlinks into <a href...> HTML tags
Dim i As Integer
For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
  With ActiveDocument.Hyperlinks(i)
   If InStr(1, .Address, "", 1) Then
      .Range = "<a href=""" & Replace(.Address, "", "") & """>" _
& Replace(Replace(.TextToDisplay, "<strong>", ""), "</strong>", "") & "</a>"
      .Range = "<a href=""" & .Address & """ target=""_blank"" rel=""nofollow"">" & _
Replace(Replace(.TextToDisplay, "<strong>", ""), "</strong>", "") & "</a>"
   End If
End With Next i End Sub

Share this article

Additional Resources for Entrepreneurs

Lists of Venture Capital and Private Equity Firms

Franchise Opportunities


Business Glossary


Conversation Board

Did you find our Word macro for converting Word hyperlinks to HTML hyperlinks to be useful? Any questions or suggestions?

Leave a Reply

Questions, Comments, Tips, and Advice

Email will not be posted or shared
Code Image - Please contact webmaster if you have problems seeing this image code

Problem Viewing Image? Load New Code