VBA MS-Word: Is it possible to replace text with wildcard?

后端 未结 2 852
南笙
南笙 2021-01-17 02:18

Is it possible to replace the text that was found using wildcard and replace it with wildcard also? for example FindText:=\"(^13{2}*^13)\", Forward:=True, MatchWildcar

相关标签:
2条回答
  • 2021-01-17 02:31

    The entire discussion in Comments is unclear, but I understand that you need to replace only part of the search term, and retain another part. Yes, that's possible by defining expressions in the search term. For example:

    Find: "(^13{2}*)^13" Replace: \1^11

    An expression is defined using parentheses. You can have multiple expressions in the "Find" text. Refer to an expression and have Word use it in the replacement using backslash+index, where index is the number (location) of the expression in the Find text. In the above example, taken from your question, there is one expression, so \1.

    0 讨论(0)
  • 2021-01-17 02:39

    I am not a word developer, but just done this, not complete solution, but a good starting point??? : Text was "Nathan testing Nathan testing"

            dim x as find    
    
        Selection.WholeStory
    
                Set x = Selection.Find
     x.Find.ClearFormatting
                x.Find.Replacement.ClearFormatting
                With x
                    .Text = "Na*han"
                    .Replacement.Text = .Text
                    .Forward = True
                    .Wrap = wdFindAsk
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchAllWordForms = False
                    .MatchSoundsLike = False
                    .MatchWildcards = True
                End With
    
                x.Execute
                x.Execute Replace:=wdReplaceOne
    
    0 讨论(0)
提交回复
热议问题