View Single Post
 
Old 09-29-2021, 04:08 PM
jeffreybrown jeffreybrown is offline Windows 10 Office 2016
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Separate text by numbers and change font

Hi All,

The first part of this I have fine with using the below. The part that isn't working is the changing of the font and color. I used the macro recorder, but apparently the syntax doesn't fit right.

Code:
Sub CleanUpLines2()
    Application.ScreenUpdating = False
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        With .Replacement.Font
            .Bold = True
            .Color = -721371137
        End With
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = True
        .Text = "([0-9]{1,2} )"
        .Replacement.Text = "^p\1"
        .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
End Sub
Here is what I got from the recorded macro.

Code:
Sub Macro6()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Bold = True
        .Color = -721371137
    End With
    With Selection.Find
        .Text = "([0-9]{1,2} )"
        .Replacement.Text = "^p\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote