I am doing a long Word search-and-replace macro in 14-line chunks exemplified
as follows:

With Selection.Find
.Text = "del^13"
.Replacement.Text = "delivery^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Of those lines above, these never change:
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Am I allowed to expunge those lines from each of the 14-line blocks since
they are always the same and, presumably, are at default values? Or do I at
most just have to keep the .Wrap statement?

Re: All search & replace lines needed? by Jezebel

Jezebel
Fri Feb 10 17:36:46 CST 2006

Yes you can omit those. Simpler still is to use a loop, with the changing
values in variables --

With Selection.Find
For i = 1 to 14
.Text = Choose(i, "del^13", "...", "..."....)
.Replacement.Text = Choose(i,"delivery^p", "...", "......)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Next
End with


"slangist" <slangist@yahoo.com> wrote in message
news:33B89791-6E8A-4F1F-BE7D-C8082BBF5243@microsoft.com...
>I am doing a long Word search-and-replace macro in 14-line chunks
>exemplified
> as follows:
>
> With Selection.Find
> .Text = "del^13"
> .Replacement.Text = "delivery^p"
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = True
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute Replace:=wdReplaceAll
>
> Of those lines above, these never change:
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
>
> Am I allowed to expunge those lines from each of the 14-line blocks since
> they are always the same and, presumably, are at default values? Or do I
> at
> most just have to keep the .Wrap statement?
>



Re: All search & replace lines needed? by Helmut

Helmut
Fri Feb 10 17:48:48 CST 2006

Hi,

all you need is this:

With ActiveDocument.Range.Find
.Text = "del^13"
.Replacement.Text = "delivery^p"
.Execute Replace:=wdReplaceAll
End With

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Re: All search & replace lines needed? by slangist

slangist
Fri Feb 10 19:13:27 CST 2006

Thanks! If I do it this way, how many entries can I have in

Text = Choose(i, "..", "...", "..."....)
and
Replacement Text = Choose(i, "..", "...", "..."....)
?

I am up to 256 terms now, with a probable upper limit of 500.

And what is the function of the

For i = 1 to 14

statement?

Appreciate all the help!

"Jezebel" wrote:

> Yes you can omit those. Simpler still is to use a loop, with the changing
> values in variables --
>
> With Selection.Find
> For i = 1 to 14
> .Text = Choose(i, "del^13", "...", "..."....)
> .Replacement.Text = Choose(i,"delivery^p", "...", "......)
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = True
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> .Execute Replace:=wdReplaceAll
> Next
> End with
>
>
> "slangist" <slangist@yahoo.com> wrote in message
> news:33B89791-6E8A-4F1F-BE7D-C8082BBF5243@microsoft.com...
> >I am doing a long Word search-and-replace macro in 14-line chunks
> >exemplified
> > as follows:
> >
> > With Selection.Find
> > .Text = "del^13"
> > .Replacement.Text = "delivery^p"
> > .Forward = True
> > .Wrap = wdFindContinue
> > .Format = False
> > .MatchCase = True
> > .MatchWholeWord = False
> > .MatchWildcards = False
> > .MatchSoundsLike = False
> > .MatchAllWordForms = False
> > End With
> > Selection.Find.Execute Replace:=wdReplaceAll
> >
> > Of those lines above, these never change:
> > .Forward = True
> > .Wrap = wdFindContinue
> > .Format = False
> > .MatchWholeWord = False
> > .MatchWildcards = False
> > .MatchSoundsLike = False
> > .MatchAllWordForms = False
> >
> > Am I allowed to expunge those lines from each of the 14-line blocks since
> > they are always the same and, presumably, are at default values? Or do I
> > at
> > most just have to keep the .Wrap statement?
> >
>
>
>

Re: All search & replace lines needed? by slangist

slangist
Fri Feb 10 19:14:27 CST 2006

Thanks for the help! Looks real elegant. But what if I need to replace, say,
"saic" with "SAIC"? Will your solution cover capitalization questions?

"Helmut Weber" wrote:

> Hi,
>
> all you need is this:
>
> With ActiveDocument.Range.Find
> .Text = "del^13"
> .Replacement.Text = "delivery^p"
> .Execute Replace:=wdReplaceAll
> End With
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>

Re: All search & replace lines needed? by Jezebel

Jezebel
Fri Feb 10 21:29:09 CST 2006

I don't know what the technical limit is for choose() -- but for more than
about a dozen items (as you have), it's impractical: it's too hard to see
what's going on with your code.

In your case, it would be better to set up an array --

Dim pText(1 to n, 1 to 2) as string
pText(1,1) = "del^p" : pText(1,2) = "delivery^p"
:

With as many items as you have, you might want to set this up in a table or
a spreadsheet, where it's easier to maintain.


For i = 1 to n
.Text = pText(i,1)
.Replacement.Text = pText(i,2)
:



The i = 1 to 14 was my misreading of your question. I thought you had 14
replacements to do.






"slangist" <slangist@yahoo.com> wrote in message
news:EF138135-E859-4262-8CCF-C91FC2684E20@microsoft.com...
> Thanks! If I do it this way, how many entries can I have in
>
> Text = Choose(i, "..", "...", "..."....)
> and
> Replacement Text = Choose(i, "..", "...", "..."....)
> ?
>
> I am up to 256 terms now, with a probable upper limit of 500.
>
> And what is the function of the
>
> For i = 1 to 14
>
> statement?
>
> Appreciate all the help!
>
> "Jezebel" wrote:
>
>> Yes you can omit those. Simpler still is to use a loop, with the changing
>> values in variables --
>>
>> With Selection.Find
>> For i = 1 to 14
>> .Text = Choose(i, "del^13", "...", "..."....)
>> .Replacement.Text = Choose(i,"delivery^p", "...", "......)
>> .Forward = True
>> .Wrap = wdFindContinue
>> .Format = False
>> .MatchCase = True
>> .MatchWholeWord = False
>> .MatchWildcards = False
>> .MatchSoundsLike = False
>> .MatchAllWordForms = False
>> .Execute Replace:=wdReplaceAll
>> Next
>> End with
>>
>>
>> "slangist" <slangist@yahoo.com> wrote in message
>> news:33B89791-6E8A-4F1F-BE7D-C8082BBF5243@microsoft.com...
>> >I am doing a long Word search-and-replace macro in 14-line chunks
>> >exemplified
>> > as follows:
>> >
>> > With Selection.Find
>> > .Text = "del^13"
>> > .Replacement.Text = "delivery^p"
>> > .Forward = True
>> > .Wrap = wdFindContinue
>> > .Format = False
>> > .MatchCase = True
>> > .MatchWholeWord = False
>> > .MatchWildcards = False
>> > .MatchSoundsLike = False
>> > .MatchAllWordForms = False
>> > End With
>> > Selection.Find.Execute Replace:=wdReplaceAll
>> >
>> > Of those lines above, these never change:
>> > .Forward = True
>> > .Wrap = wdFindContinue
>> > .Format = False
>> > .MatchWholeWord = False
>> > .MatchWildcards = False
>> > .MatchSoundsLike = False
>> > .MatchAllWordForms = False
>> >
>> > Am I allowed to expunge those lines from each of the 14-line blocks
>> > since
>> > they are always the same and, presumably, are at default values? Or do
>> > I
>> > at
>> > most just have to keep the .Wrap statement?
>> >
>>
>>
>>



Re: All search & replace lines needed? by Helmut

Helmut
Sat Feb 11 04:29:30 CST 2006

Hi,

I didn't get what that 14 line chunks were about:

With ActiveDocument.Range.Find
.Text = "DEL^13"
.Replacement.Text = "delivery^p"
.MatchCase = True
.Execute Replace:=wdReplaceAll
End With

Instead of activedocument.range you may define
your own ranges and loop trough them,
as Jezebel suggested.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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