Find multiple items and replace multiple items

M

Macro''''er

Hello,

I'm looking for a macro to replace multiple items such as below. I have
Word 2003. I appreciate any help you can provide. Thanks!

Find: "One" Replace with "One (1)"
Find: "Two" Replace with "Two (2)"
Find: "Three" Replace with Three (3)"
....and so on and so forth.
 
M

Macro''''er

Thank you, but is there a macro I can execute at once to do all find and
replace as indicated without having to find and replace one word at a time?
 
M

Macro''''er

The VBA Find and Replace macro is perfect, but I'm looking for a simple macro
i can imbed in my document to find and replace a predefined list.

Thank you.
 
G

Greg Maxey

This will only work in the main text story but it could be made to work in
all stories:

Sub FRUsingArrays()
Dim SearchArray As Variant
Dim ReplaceArray As Variant
Dim myRange As Range
Dim i As Long
Dim pFind As String
Dim pReplace As String
SearchArray = Array("one", "two", "three")
ReplaceArray = Array("one (1)", "two (2)", "three (3)")
Set myRange = ActiveDocument.Range
For i = LBound(SearchArray) To UBound(SearchArray)
pFind = SearchArray(i)
pReplace = ReplaceArray(i)
With myRange.Find
.Text = pFind
.Replacement.Text = pReplace
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
 
R

Russ

Macroer,
A slight modification to Graham's nice subroutine may allow for easier setup
by using only one array.

Sub FRUsingArray()
Dim SearchArray As Variant
Dim myRange As Range
Dim i As Long
Dim pFind As String

SearchArray = Array("one", "two", "three")
'The lower bound of an array created using the _
Array function is always zero. Unlike other types _
of arrays, it is not affected by the lower bound _
specified with the Option Base statement.
Set myRange = ActiveDocument.Range
For i = LBound(SearchArray) To UBound(SearchArray)
pFind = SearchArray(i)
With myRange.Find
.Text = pFind
.Replacement.Text = pFind & " (" & i + 1 & ")"
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
 
H

Helmut Weber

Hi everybody,

remains the problem of the OP of
Find: "One" Replace with "One (1)"
Find: "Two" Replace with "Two (2)"
Find: "Three" Replace with Three (3)"
...and so on and so forth."<<<

which can be solved by some code written by
Greg Maxey and Doug Robbins.

http://gregmaxey.mvps.org/Spell_Out_Currency.htm

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top