How to hyperlink Email addresses and URLs?

G

Graeme

Hi All

I call this function to hyperlink typed URLs, but there must surely be a
better way. What I would like is something better to 1) automatically
hyperlink URLs when clicked, and 2) same for Email addresses. Must have been
done many times before more efficiently than this. Please can someone help?

Function LinkURLs(ByVal strInput) 'called from POST button_click
Dim iCurrentLocation

Dim iLinkStart

Dim iLinkEnd

Dim strLinkText

Dim strOutput

iCurrentLocation = 1

Do While InStr(iCurrentLocation, strInput, "http://", 1) <> 0

iLinkStart = InStr(iCurrentLocation, strInput, "http://", 1)

iLinkEnd = InStr(iLinkStart, strInput, " ", 1)

If iLinkEnd = 0 Then iLinkEnd = Len(strInput) + 1

Select Case Mid(strInput, iLinkEnd - 1, 1)

Case ".", "!", "?"

iLinkEnd = iLinkEnd - 1

End Select

strOutput = strOutput & Mid(strInput, iCurrentLocation, iLinkStart -
iCurrentLocation)

strLinkText = Mid(strInput, iLinkStart, iLinkEnd - iLinkStart)

strOutput = strOutput & "<A HREF=""" & strLinkText & """ target=""_blank"">"
& strLinkText & "</A>"

iCurrentLocation = iLinkEnd

Loop

strOutput = strOutput & Mid(strInput, iCurrentLocation)

LinkURLs = strOutput

End Function

Thanks for your assistance
Graeme
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top