正则表达式,但保持字体格式?

时间:2011-05-31 09:52:20

标签: regex vba ms-word

Previously I asked for help with a word VBA macro regex

执行此操作时是否有办法维护字体格式?

1 个答案:

答案 0 :(得分:1)

不是很优雅,但这不是你想要的(或者你的意思是你想用一个'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