View Single Post
 
Old 10-16-2023, 01:32 PM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 293
vivka is on a distinguished road
Default

Hi, Lydia90! The code is simple and it does what you want. I added an inputbox in case you want to find sth else. Selection allows working on any selected range incl. the active document (Ctrl+A)
Code:
Sub Uppercase_Stri()
'In slection, find all instances of the inputboxed string
'and capitalize all their letters.

Dim myRng As range
Dim stri As String

Set myRng = selection.range
    stri = InputBox("Enter the string to find")
    With myRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .text = stri
        .Replacement.Font.AllCaps = True
        .Forward = True
        .Format = True
        .MatchCase = True
        .MatchWholeWord = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .MatchWildcards = False
        .Wrap = wdFindStop
        .Execute Replace:=wdReplaceAll
    End With
End Sub
Reply With Quote