PDA

View Full Version : Find/Replace through file



Ethen5155
11-02-2019, 05:42 PM
Hi all,

i'm trying to find a way to make several find/replace through file with a specific criteria as following:

this text:

m:para-id="0"

is repeated more than 200 times at the file, i want to find them and go through file then replace to

m:para-id="1-tu1"
m:para-id="1-tu1"
m:para-id="1-tu2"
m:para-id="1-tu2"
m:para-id="1-tu3"
m:para-id="1-tu3"
m:para-id="1-tu4"
m:para-id="1-tu4"

.......etc

in other words i need to find the first two instances and change the "0" to "1-tu1"
then the second two instances and change thethe "0" to "1-tu2" .....etc


25367

i have attache sample file for before and after


Thanks in advance

mana
11-02-2019, 07:46 PM
Option Explicit


Sub test()
Dim r As Range
Dim n As Long

Set r = ActiveDocument.Range

With r.Find
.Text = "(m:para-id=)""0"""
.MatchWildcards = True
Do
.Replacement.Text = "\1""1-tu" & Int(n / 2 + 1) & """"
.Execute Replace:=wdReplaceOne
r.Collapse wdCollapseEnd
If .Found = False Then Exit Do
n = n + 1
Loop
End With

End Sub



マナ