1
votes

I want to add a subroutine into my Word 2007 macro that will take the text and address for an embedded link in a document, and convert it to an href tag that uses the text as the display text, and the address for the HTML address.

So a line that appears as "go here to get to google" with a blue underline, and when clicked goes to www.google.com, gets replaced with:

<a target="_blank" href="http://www.google.com">go here to get to google</a>

This routine is to be added to an existing macro that I already have that does some other minor formatting, so no need for headers and whatnot.

1

1 Answers

0
votes

This will print the HTML tags as you specify for all of the links in your document.

Dim hlink As Hyperlink
Dim htmlLink As String

For Each hlink In ThisDocument.Hyperlinks
    With hlink
        htmlLink = "<a target=""_blank"" href=""" & .Address & """>" & _
            .TextToDisplay & "</a>"

        Debug.Print htmlLink
    End With
Next hlink

Of course, you'll want to do something more useful with them than just print them in the Immediate window.

As an aside, I prefer to use DuckDuckGo in my examples due its much better privacy policy than Google's...