Share via

Word find font 14 only

Anonymous
2024-11-23T01:06:40+00:00

Helllo from Steve

The below is finding Fonts 12 and Fonts 14

How do I please only find Font 14

Sub Australia_Dollar_Highlight()

Selection.Find.Font.Size = 14 

Options.DefaultHighlightColorIndex = wdYellow 

With Selection.Find 

    .ClearFormatting 

    .Text = "($[0-9,]{1,})" 

    .Forward = True 

    .Wrap = wdFindContinue 

    .Format = True 

    .MatchCase = False 

    .MatchWholeWord = False 

    .MatchAllWordForms = False 

    .MatchSoundsLike = False 

    .MatchWildcards = True 

    With .Replacement 

        .Text = "\1" 

        .ClearFormatting 

        With .Font 

        .Font.Size = 14 

        .Bold = True 

        .Color = wdColorRed 

        End With 

        .Highlight = True 

    End With 

    .Execute Replace:=wdReplaceAll 

End With 

End Sub

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

Answer accepted by question author

Anonymous
2024-11-23T05:16:39+00:00

Hi Steve8d,

Thanks for visiting Microsoft Community.

The purpose of the code you provided seems to be to find text that matches a specific pattern (i.e., numbers starting with a dollar sign) in the selected part of a Word document and set its font size to 14, make it bold, red, and highlighted. To make it only apply to text with a font size of 14, you can add a check for the font size in the find and replace section. Here is the modified code:

Sub Australia_Dollar_Highlight() 

    Options.DefaultHighlightColorIndex = wdYellow 

    With Selection.Find 

        .ClearFormatting 

        .Text = "($[0-9,]{1,})" 

        .Forward = True 

        .Wrap = wdFindContinue 

        .Format = True 

        .MatchCase = False 

        .MatchWholeWord = False 

        .MatchAllWordForms = False 

        .MatchSoundsLike = False 

        .MatchWildcards = True 

        .Font.Size = 14

        With .Replacement 

            .Text = "\1" 

            .ClearFormatting 

            With .Font 

                .Size = 14 

                .Bold = True 

                .Color = wdColorRed 

            End With 

            .Highlight = True 

        End With 

        .Execute Replace:=wdReplaceAll 

    End With 

End Sub 

Here are the test results.

You need to select the text you want to format before running the code.

If you have any issues, please feel free to reply.

Best Regards,

Jonathan Z - MSFT | Microsoft Community Support Specialist

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2024-11-23T06:20:03+00:00

    Hello Jonathan

    I thank you.

    All the Best

    Steve

    Was this answer helpful?

    0 comments No comments