3
votes

I have a word document that is littered with hyperlinks. The links themselves work fine, but for some reason, most of them are not blue anymore! All I'm really looking to do is try to find a way to use a macro or something to go through the document and add the "Hyperlink" style format to each hyperlink.

I tried to edit some macro code myself (one that changes all the links URLs), but I keep making the problem worse! I used to be good at VBScript, but it's been ages since then.

Any easy solution that doesn't involve manually changing each style?

As a side note, all of them currently are in "Normal" style, for some reason.

1
Welcome to SO, Robert! What color are the links now if not the blue you are expecting? Are they purple (indicating they have previously been clicked)?Brian
Thanks! No, they're black like plain text. Some of them have blue underlines and some don't. I don't believe it's a previously clicked thing.Robert

1 Answers

5
votes

Try to execute this VBA script (best in debugging mode using the F8 key - have VBA and Word windows side by side so you can see what's happening):

Sub FormatLinks()
Dim H As Hyperlink

    For Each H In ActiveDocument.Hyperlinks
        H.Range.Select                                      ' (A)
        Selection.ClearFormatting                           ' (B)

        H.Range.Style = ActiveDocument.Styles("Hyperlink")  ' (C)
    Next H
End Sub

This will

  • cycle through all hyperlinks in your document (A),
  • remove any formatting on the underlying text (B) and
  • assign the undrelying text to style "Hyperlink" (C)

(C) is not strictly necessary, as (B) should already sanitize your document, but maybe better to have hyperlinks really assigned to style "Hyperlink" because you may want to change the style later on.