Helen269
09-13-2022, 06:21 PM
I have this sub below which clears hyperlinks from links. It works, but there's an oddity about it.
If I copy and paste into Word some text that contains hyperlinks and then run this code immediately, it strips the formatting from the links. Blue underlined text becomes black with no underline. Ugly.
But if I paste in the text and save the document, exit Word, and then load the same document back up again, I can run this code and it won't strip the hyperlink formatting. Blue underlined text stays as blue underlined text.
It took me a while to figure out how to stop the formatting stripping, but I'm just wondering... why is it doing that? What's going on?
Sub ClearHyperlinks()
Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldHyperlink Then
oField.Unlink
End If
Next
Set oField = Nothing
End Sub
If I copy and paste into Word some text that contains hyperlinks and then run this code immediately, it strips the formatting from the links. Blue underlined text becomes black with no underline. Ugly.
But if I paste in the text and save the document, exit Word, and then load the same document back up again, I can run this code and it won't strip the hyperlink formatting. Blue underlined text stays as blue underlined text.
It took me a while to figure out how to stop the formatting stripping, but I'm just wondering... why is it doing that? What's going on?
Sub ClearHyperlinks()
Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldHyperlink Then
oField.Unlink
End If
Next
Set oField = Nothing
End Sub