Changing the Color of Hyperlinks

Anonymous
2022-06-17T09:11:37+00:00

In Microsoft Word, hyperlinks have the default color RGB(5, 99, 193). When I use the following script to change the color of all hyperlinks found within a selection from RGB(5, 99, 193) to RGB(0, 176, 240), nothing happens.

Does anyone know how to change the color of links within a selection to the specified color?

Selection.Find.ClearFormatting

 Selection.Find.Font.Color = RGB(5, 99, 193)

 Selection.Find.Replacement.ClearFormatting

 Selection.Find.Replacement.Font.Color = RGB(0, 176, 240)

With Selection.Find

 .Text = ""

 .Replacement.Text = ""

 .Forward = True

 .Wrap = wdFindStop

 .Format = True

 End With

 Selection.Find.Execute Replace:=wdReplaceAll

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Jay Freedman 206K Reputation points Volunteer Moderator
    2022-06-18T13:42:32+00:00

    I don't know why the Replace dialog can't recognize the RGB font color of text that has the Hyperlink style (which, by the way, in my Word program from Microsoft 365 has the value RGB(0,80,253)). But if you use Format > Style > Hyperlink in the Find What box and the desired font color in the Replace With box, the Replace All button will replace the color of hyperlinks in the selected text; then you have to click No in the message that asks whether to search the rest of the document.

    To do this with a macro, try this:

    Sub ChangeHyperlinkColor() 
    
        Dim rg As Range 
    
        Set rg = Selection.Range 
    
        rg.Collapse wdCollapseStart 
    
        With rg.Find 
    
            .Format = True 
    
            .Style = "Hyperlink" 
    
            .Forward = True 
    
            .Wrap = wdFindStop 
    
            While .Execute And rg.InRange(Selection.Range) 
    
                rg.Font.TextColor = RGB(0, 176, 240) 
    
                rg.Collapse wdCollapseEnd 
    
            Wend 
    
        End With 
    
    End Sub
    
    5 people found this answer helpful.
    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Suzanne S Barnhill 275K Reputation points MVP Volunteer Moderator
    2022-06-17T11:13:09+00:00

    Instead of using a macro, just redefine the color of the Hyperlink and Followed Hyperlink character styles.

    1 person found this answer helpful.
    0 comments No comments
  2. Charles Kenyon 160K Reputation points Volunteer Moderator
    2022-06-17T11:40:03+00:00

    Is there some reason you want to do this only on selected text?

    Otherwise, the best method is that given by Suzanne.

    0 comments No comments
  3. Anonymous
    2022-06-17T12:58:03+00:00

    Is there some reason you want to do this only on selected text?

    Otherwise, the best method is that given by Suzanne.

    Yes, I want hyperlinks within certain text segments to have a different color. Therefore, I need to select certain segments and automatically change the color of all hyperlinks within the selection.

    0 comments No comments
  4. Jay Freedman 206K Reputation points Volunteer Moderator
    2022-06-17T16:20:29+00:00

    To start, create a new character style based on the Hyperlink style (here I've named the new style Hyperlink2, but you can choose what you like) and change only the font color in the dialog:

    Then create a macro like the other color-changer macros we've discussed, but to change the style. Where "Hyperlink2" appears in the code, insert the actual name of your new style.

    Sub ChangeHyperlinkStyle() 
    
        Dim rg As Range 
    
        Set rg = Selection.Range 
    
        rg.Collapse wdCollapseStart 
    
        With rg.Find 
    
            .Format = True 
    
            .Style = "Hyperlink" 
    
            .Forward = True 
    
            .Wrap = wdFindStop 
    
            While .Execute And rg.InRange(Selection.Range) 
    
                rg.Style = "Hyperlink2" 
    
                rg.Collapse wdCollapseEnd 
    
            Wend 
    
        End With 
    
    End Sub
    
    1 person found this answer helpful.
    0 comments No comments