A macro for multiple find and replace

I have a PDF file. When I copy text from PDF and past it in word it shows it like:

‰`ò  Õ``ç£``â  „`≈øù  gZ  /gZfd  z  fzd  f£``≈±Ö  x£``ûZÆ`ô yÆ``Gç  f£``ò  z  Õ`çÍ£``Ö  f£``≈±Ö  £``õ  x£``Ög

I can understand from the original text that  I should replace "Æ"  with "r",    "‰"   with "h" and ... to get a meaningful text.
I made an excel sheet with the 2 columns. The characters in the first column should be replaced by the corresponding characters in the second columns.

I remember that  somebody here introduced a word macro to do multiple find and replacement using an excel file. But now I can not find it. Can anybody help me?!

Something that should be considered is that the coresponding characters for capital and lowercase letters are different. for example "Õ" corresponds to "k" but the lower case "õ"  corresponds to "m"


Question Info

Last updated February 17, 2019 Views 2,154 Applies to:

Hi McKazie,

Try something along the lines of:

Sub MultiReplace()
Dim StrOld As String, StrNew As String
Dim RngFind As Range, RngTxt As Range, i As Long
StrOld = "the,quick,brown,fox"
StrNew = "The,Quick,Brown,Fox"
Set RngTxt = Selection.Range
For i = 0 To UBound(Split(StrOld, ","))
  Set RngFind = RngTxt.Duplicate
  With RngFind.Find
    .Text = Split(StrOld, ",")(i)
    .Replacement.Text = Split(StrNew, ",")(i)
    .Format = False
    .MatchWholeWord = True
    .MatchAllWordForms = False
    .MatchWildcards = False
    .Execute Replace:=wdReplaceAll
  End With
End Sub

Simply input the comma-separated letters for the two sets of characters into the StrOld and StrNew variables. All this can be done in Word, without the need for an external file/list.

Paul Edstein
[MS MVP - Word]

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.