Share via

Word I have two fonts 10.5 and 12

SteveD 435 Reputation points
2026-04-12T22:13:20.2233333+00:00

Hello from Steve

I have two fonts 10.5 and 12

Please how do I execute font 12 only not 10.5

Sub BarrierDrawColoured()

 First4 "( 1)"

 First4 "( 2)"

 First4 "( 3)"

 First4 "( 4)"
``` End Sub

Sub First4(sText As String)

Selection.HomeKey Unit:=wdStory

With Selection.Find

.ClearFormatting

.Text = sText

.Forward = True

.Wrap = wdFindStop

.Format = True

.MatchCase = True

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

Do While .Execute

    Selection.MoveLeft Unit:=wdCharacter, Count:=1

    Selection.MoveRight Unit:=wdCharacter, Count:=2

    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend

    Selection.Find.Font.Size = 12

    Selection.Font.Bold = True

    Selection.Font.Color = wdColorRed

    Selection.range.HighlightColorIndex = wdYellow

    Selection.Collapse Direction:=wdCollapseEnd

Loop

End With


Developer technologies | Visual Basic for Applications

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-04-12T22:13:28.6333333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Set the Find formatting to font size 12 before executing the loop, instead of setting Selection.Find.Font.Size inside the loop. For example:

    Sub BarrierDrawColoured()
    
        First4 "( 1)"
        First4 "( 2)"
        First4 "( 3)"
        First4 "( 4)"
    
    End Sub
    
    Sub First4(sText As String)
    
        Selection.HomeKey Unit:=wdStory
    
        With Selection.Find
            .ClearFormatting
            .Text = sText
            .Forward = True
            .Wrap = wdFindStop
            .Format = True
            .MatchCase = True
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
    
            ' Only find text that has font size 12
            .Font.Size = 12
    
            Do While .Execute
                Selection.MoveLeft Unit:=wdCharacter, Count:=1
                Selection.MoveRight Unit:=wdCharacter, Count:=2
                Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    
                Selection.Font.Bold = True
                Selection.Font.Color = wdColorRed
                Selection.Range.HighlightColorIndex = wdYellow
    
                Selection.Collapse Direction:=wdCollapseEnd
            Loop
        End With
    
    End Sub
    

    Key change: .Font.Size = 12 is applied to the Find object (With Selection.Find) before Do While .Execute, so only occurrences in 12‑point text are found and processed. The line Selection.Find.Font.Size = 12 inside the loop is removed because it does not affect which text is found.


    References:

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.