View Single Post
 
Old 11-03-2019, 10:30 PM
barrskog barrskog is offline Windows 10 Office 2019
Novice
 
Join Date: Nov 2019
Posts: 2
barrskog is on a distinguished road
Default Rookie help with actually writing a macro

Hi!

I'm a Word and programming rookie, but eager to learn more. I'm looking to create a simple find and replace macro, and I've been searching the forums (and googling for other tips) and there's of course plenty of solutions out there. However, I can get the macro to work even when copying the text and replace the Words in the macro that I want to replace. So obviously I'm missing out on something.

The Words I want to replace is:
qq,ohb,krp,ljd,§
With:
<olp>,<spn>,<vocalized_noise>,<noise>,(nothing, ie removed)

The macro I've find which I Think should do this is the one below. However, I'm getting red lines and syntax errors when posting it in the editor. I would be very happy if someone could Point out whats the problem and help me get a macro that can be copy pasted. Yes - I'm that rookie.


Sub MultiReplace()
Dim StrOld As String, StrNew As String
Dim RngFind As Range, RngTxt As Range, i As Long
StrOld = &quot;qq,ohb,krp,ljd,§&quot;
StrNew = &quot;<olp>,<spn>,<vocalized_noise>,<noise>,&qu ot;
Set RngTxt = Selection.Range
For i = 0 To UBound(Split(StrOld, &quot;,&quot)
Set RngFind = RngTxt.Duplicate
With RngFind.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = Split(StrOld, &quot;,&quot(i)
.Replacement.Text = Split(StrNew, &quot;,&quot(i)
.Format = False
.MatchWholeWord = True
.MatchAllWordForms = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
Reply With Quote