View Single Post
 
Old 08-05-2023, 02:18 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will change the style of the word 'description' if in upper case or starting a sentence.
Note that the macro calls a character style - here the built-in style 'Strong'. If you call a paragraph style the chances are that the whole paragraph containing the word will be so formatted, so I suggest creating a character style to achieve the formatting you require.
Code:
Sub Macro1()
Dim oRng As Range
Dim vFind As Variant
Dim i As Integer
    vFind = Array("DESCRIPTION", "Description")
    For i = 0 To UBound(vFind)
        Set oRng = ActiveDocument.Range
        With oRng.Find
            .ClearFormatting
            .Text = vFind(i)
            Do While .Execute(findText:=vFind(i), MatchWholeWord:=True, MatchCase:=True)
                oRng.Style = "Strong" 'Change as appropriate
            Loop
        End With
    Next i
    Set oRng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote