0
votes

Previously I asked for help with a word VBA macro regex.

Is there a way to maintain font formatting when doing this?

1

1 Answers

1
votes

Not very elegant, but is this not what you want (or do you mean that you want to replace the entire contents with a single '0')?

Sub Macro1()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^$*"
        .Replacement.Text = "0"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub