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 / February 2006

Tip: Looking for answers? Try searching our database.

All search & replace lines needed?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
slangist - 10 Feb 2006 23:15 GMT
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?
Jezebel - 10 Feb 2006 23:36 GMT
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

>I am doing a long Word search-and-replace macro in 14-line chunks
>exemplified
[quoted text clipped - 27 lines]
> at
> most just have to keep the .Wrap statement?
slangist - 11 Feb 2006 01:13 GMT
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!

> Yes you can omit those. Simpler still is to use a loop, with the changing
> values in variables --
[quoted text clipped - 46 lines]
> > at
> > most just have to keep the .Wrap statement?
Jezebel - 11 Feb 2006 03:29 GMT
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.

> Thanks! If I do it this way, how many entries can I have in
>
[quoted text clipped - 65 lines]
>> > at
>> > most just have to keep the .Wrap statement?
Helmut Weber - 10 Feb 2006 23:48 GMT
Hi,

all you need is this:

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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

slangist - 11 Feb 2006 01:14 GMT
Thanks for the help! Looks real elegant. But what if I need to replace, say,
"saic" with "SAIC"? Will your solution cover capitalization questions?

> Hi,
>
[quoted text clipped - 5 lines]
>    .Execute Replace:=wdReplaceAll
> End With
Helmut Weber - 11 Feb 2006 10:29 GMT
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.

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.