M
M
madnessi2019-07-11 20:42:25
Visual Basic
madnessi, 2019-07-11 20:42:25

How to register a macro for to replace a combination of characters?

You need to write a macro for Word so that ", - " is replaced by "", - ".

Selection.Find.Execute Replace:=wdReplaceAll
      With Selection.Find
        .Text = ", - "
        .Replacement.Text = "^34^44 ^45 "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

Neither "^44 ^45 " nor """, - " work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lvv85, 2019-07-11
@lvv85

With Selection.Find
        .Text = ", -"
        .Replacement.Text = """, -"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question