View Single Post
 
Old 11-06-2021, 11:26 PM
laith93 laith93 is offline Windows 10 Office 2019
Competent Performer
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Post Using custom style instead of inserting font attributes manually in VBA code

Hi,
I have this code to change attributes of multiple words, which requires to type it manually each time, but I want to use custom style.
I edited the code by inserting the line which marked in red color, but doesn't make changes. Any solution please with thanks.
Code:
Sub SearchMultipleWords()
    Dim oDoc As Document
    Dim MyAr() As String, strToFind As String
    Dim i As Long
    strToFind = "Background, Methods, Results, Conclusion"
    MyAr = Split(strToFind, ",")
    For i = LBound(MyAr) To UBound(MyAr)
        With selection.Find
            .ClearFormatting
            .Text = MyAr(i)
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Execute

            '~~> Change the attributes
            Do Until .Found = False
            With Selection.Style = ActiveDocument.Styles("B12")
'                With Selection.Font
'                    .Name = "Times New Roman"
'                    .Size = 12
'                    .Bold = True
'                   ' .Color = RGB(200, 200, 0)
''                    .Italic = True
                End With
                Selection.Find.Execute
            Loop
        End With
    Next i
End Sub
Reply With Quote