Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Find multiple items and replace multiple items

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Macro''''er - 23 Oct 2007 07:10 GMT
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.

Signature

Smile...it is good for you!  :)

Greg Maxey - 23 Oct 2007 12:52 GMT
This will do it:
http://gregmaxey.mvps.org/VBA_Find_And_Replace.htm

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hello,
>
[quoted text clipped - 5 lines]
> Find: "Three" Replace with Three (3)"
> ...and so on and so forth.
Macro''''er - 23 Oct 2007 16:36 GMT
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?

Signature

Smile...it is good for you!  :)

> This will do it:
> http://gregmaxey.mvps.org/VBA_Find_And_Replace.htm
[quoted text clipped - 8 lines]
> > Find: "Three" Replace with Three (3)"
> > ...and so on and so forth.
Macro''''er - 23 Oct 2007 16:43 GMT
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.

Signature

Smile...it is good for you!  :)

> 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?
[quoted text clipped - 11 lines]
> > > Find: "Three" Replace with Three (3)"
> > > ...and so on and so forth.
Greg Maxey - 23 Oct 2007 22:20 GMT
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

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> The VBA Find and Replace macro is perfect, but I'm looking for a simple
> macro
[quoted text clipped - 19 lines]
>> > > Find: "Three" Replace with Three (3)"
>> > > ...and so on and so forth.
Russ - 24 Oct 2007 06:10 GMT
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

> This will only work in the main text story but it could be made to work in
> all stories:
[quoted text clipped - 44 lines]
>>>>> Find: "Three" Replace with Three (3)"
>>>>> ...and so on and so forth.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Helmut Weber - 24 Oct 2007 15:35 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.