May 29, 2020  
 
Gaebler.com is a daily online magazine covering small business news. We help entrepreneurs transform ideas and innovations into greatness.

Articles for Entrepreneurs

 

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 "http://www.gaebler.com" 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, "http://www.gaebler.com", 1) Then
      .Range = "<a href=""" & Replace(.Address, "http://www.gaebler.com", "") & """>" _
& Replace(Replace(.TextToDisplay, "<strong>", ""), "</strong>", "") & "</a>"
   Else
      .Range = "<a href=""" & .Address & """ target=""_blank"" rel=""nofollow"">" & _
Replace(Replace(.TextToDisplay, "<strong>", ""), "</strong>", "") & "</a>"
   End If
End With Next i End Sub

Conversation Board

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


Questions, Comments, Tips, and Advice  Code Image - Please contact webmaster if you have problems seeing this image code
Problem Viewing Image
Load New Code

 

 

Additional Resources for Entrepreneurs

Search Engine Marketing

Social Marketing Optimization

Business Forms

Business in the Jungle - Business in Fiction - Negotiating

Radio Ad Costs

Newspaper Advertising Rates

City-Specific Resources for Entrepreneurs

Small Business Insurance

Global Entrepreneurship

China & Entrepreneurs