[How To] Remove Hyperlinks in MS Word using Visual Basic

how-to-bw

Documents may contain hyperlinks to other documents or web pages. Hyperlinks typically appear as blue underlined text strings.To manually delete a single hyperlink from a document, right-click the hyperlink, point to Hyperlink on the shortcut menu, and then click Remove Hyperlink.

If you want to delete all hyperlinks in a document, you can use a Visual Basic for Applications macro to do this. The following sample Visual Basic for Applications macro removes all hyperlinks in a document.

NOTE: In the following sample macro, only the link is removed. The text of the hyperlink remains in the document.

Sub RemoveHyperlinks()

Dim oDoc As Document
Dim oStory As Range
Dim oHlink As Hyperlink
For Each oStory In ActiveDocument.StoryRanges
    For Each oHlink In oStory.Hyperlinks
        oHlink.Delete
    Next
Next
End Sub

To remove all traces of both the hyperlink and the text of the hyperlink from the document, you can use the following sample macro instead.

Sub RemoveAllHyperlinks()
Dim oDoc As Document
Dim oStory As Range
Dim oHlink As Hyperlink
For Each oStory In ActiveDocument.StoryRanges
    For Each oHlink In oStory.Hyperlinks
        oHlink.Range.Delete
    Next
Next
End Sub