سؤال

I found this macro to replace multiple strings at once in Microsoft Word 2010.

I am having trouble with the special characters. I recorded a macro and replaced the characters manually so I could see how the special characters should be written in the VBA code.

When I try to put them all together in a string it is like they are ignored.

How do I replace everything including the special characters?

ChrW(728) is ˘

and

ChrW(711) is ˇ

Sub MultiReplace()
Dim StrOld As String, StrNew As String
Dim RngFind As Range, RngTxt As Range, i As Long
StrOld = "ChrW(728),ChrW(711),H"
StrNew = ".,Þ,¼"
Set RngTxt = Selection.Range
For i = 0 To UBound(Split(StrOld, ","))
  Set RngFind = RngTxt.Duplicate
  With RngFind.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = Split(StrOld, ",")(i)
    .Replacement.Text = Split(StrNew, ",")(i)
    .Format = False
    .MatchCase = True
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchWildcards = False
    .Execute Replace:=wdReplaceAll
  End With
Next
End Sub
هل كانت مفيدة؟

المحلول

I figured it out. Replacing this line:

StrOld = "ChrW(728),ChrW(711),H"

with

StrOld = "" & ChrW(728) & "," & ChrW(711) & ",H"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top