Tuesday, November 29, 2011

Convert Hyperlinks To Proper Case

I create small files "TableOfContents" for use in my web pages.

Visit www.ChrisGreaves.com for this image! ProperCase_001.png

By mis-adventure I often enough end up with hyperlinks in a mish-mash of cases.

I'd like all the hyperlinks to conform to a consistent standard.

Sub ConvertHyperlinksToProperCase()

Dim HLNK As Hyperlink

For Each HLNK In ActiveDocument.Hyperlinks

With HLNK

Dim strTextToDisplay As String

strTextToDisplay = .TextToDisplay

.TextToDisplay = StrConv(strTextToDisplay, vbProperCase)

End With

Next HLNK

End Sub

This little macro does that.

Visit www.ChrisGreaves.com for this image! ProperCase_002.png

Note that it processes EVERY hyperlink in the current document, which is fine for me.

If you wanted it to operate only on a selected area you could change one line to read

For Each HLNK In Selection.Hyperlinks