martok
martok

Reputation: 479

Regex but maintain font formatting?

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

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

Upvotes: 0

Views: 916

Answers (1)

FrostbiteXIII
FrostbiteXIII

Reputation: 891

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

Upvotes: 1

Related Questions