I have inherited a number of document template with embedded macro's.

The WITH.SELECTION.FIND code that you posted on 2005/07/21 repeats
throughout these macro's. We are taking a report that is in multiple
paragraph form and converting it to tabbed columns, with BOLD, CENTERED
headings; some paragraph text; certain words BOLD.

Anyway, lots of manipulation of the text. I've done various types of
programming fo over 35 years -- VBA and I have a severe adversarial
relationship.

To the point:

You use the .EXECUTE within the WITH LOOP. The code I have uses either a
SELECTION.FIND.EXECUTE or SELECTION.FIND.EXECUTE . . .REPLACE ALL immediately
AFTER the END WITH

What's the difference? Also, can I use IF-THEN-ELSE constructs within the
WITH statement depending on certain conditions.

I'm trying to transform this WITH LOOP into a SUB FINDREPLACE(Param1,
Param2. . .) construct.

Thanks

Phil Montgomery

Re: Helmut Weber -- Info please by Helmut

Helmut
Fri Jul 22 16:23:40 CDT 2005

Hi Phil,

it's pretty difficult to find anything
I posted on 2005/07/21 regarding "selection.find",
as my newsreader shows all dates and times in
Central European Daylightsavings Time.
Might be a day's difference to where You are.

>You use the .EXECUTE within the WITH LOOP. The code I have uses either a
>SELECTION.FIND.EXECUTE or SELECTION.FIND.EXECUTE . . .REPLACE ALL immediately
>AFTER the END WITH

>What's the difference?

Perhaps only a matter of style.
Perhaps easier to read, perhaps only to me.
Perhaps shorter code executes faster, not to say, very likely.

By the way, unless trying to help beginners or programmers
at an intermediate level, I'm using range instead of selection.

However, having cleared search options ("resetsearch"),
I find this hard to top according speed and readability:

dim rngDcm as range
set rngdcm = activedocument.range
with rngdcm.find
.text = "Hi"
while .execute
' as long as execution is successfull
' no need of "if .found" or "while .found"
wend
end with

>Also, can I use IF-THEN-ELSE constructs within the
>WITH statement depending on certain conditions.

Sure. "Select case" also.

while .execute
if rngdcm.text = "is" then
' ...
else
'....
end if
' collapse the range to it's end if you change it's contents
wend

Need more information to be at your service.

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

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

Re: Helmut Weber -- Info please by PhilMontUSDA

PhilMontUSDA
Fri Jul 22 20:39:02 CDT 2005

Well, I'm in Orlando, FL -- Hurricane Capital of the U.S.; I'm in Eastern
Daylight Time. Since the Microsoft Server is in Washington State --
everything is posted as Pacific Daylight Time. Then to really confuse me, I
work with a system that lists every thing as nn:nn GMT +N or -N, where N is
the time zone differential between me and GMT. Reminds me of the '70s tune
-- does anybody really know what time it is.

To the point

This is the FindReplace SUBroutine I've written. It seems to work, except
where I set FwdTrue = FALSE

------------------------------------------------------------------------------------

Sub FindReplace(ByRef OriginString, NewString, FwdTrue, FormatTrue,
MatchCaseTrue, WhlWordTrue, IfOption)
'
' Macro created: 31-JANUARY-2005 by Philip H. Montgomery
'
With Selection.Find
.Text = OriginString
.Replacement.Text = NewString
If FwdTrue = 1 Then
.Forward = True
Else
.Forward = False
End If
If FormatTrue = 1 Then
.Format = True
Else
.Format = False
End If
If MatchCaseTrue = 1 Then
.MatchCase = True
Else
.MatchCase = False
End If
If WhlWordTrue = 1 Then
.MatchWholeWord = True
Else
.MatchWholeWord = False
End If
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

If IfOption = 0 Then
Selection.Find.Execute
Else
Selection.Find.Execute Replace:=wdReplaceAll
End If

End Sub

----------------------------------------------------------------------

THis is a sample of the code that I was given. Imagine enough repetitions
of this that you get
a message that basically your module is TOO BIG (too much code)!!!

'- - - - - - - - - - - - - - - - - - - - - -
'
' Correct FOB breaks in Original
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("FLVegText")
Selection.Find.Replacement.ClearFormatting
'
'- - - - - - - - - - - - - - - - - - - - - -
'

With Selection.Find
.Text = "^p baskets"
.Replacement.Text = "baskets"
.Forward = True

.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

'
'- - - - - - - - - - - - - - - - - - - - - -

This is code I modified to make things a little easier to deal with

'- - - - - - - - - - - - - - - - - - - - - -
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("FLVegText")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("FLVegLAlignHdg")
'
'- - - - - - - - - - - - - - - - - - - - - -
'
Call FindReplace("Flesh Seeded", "FLESH SEEDED", 1, 1, 1, 1, 1)
'
'- - - - - - - - - - - - - - - - - - - - - -
'
Call FindReplace("Flesh Seedless", "FLESH SEEDLESS", 1, 1, 1, 1, 1)
'
'- - - - - - - - - - - - - - - - - - - - - -
'

This is what the original looked like.


Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("FLVegText")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("FLVegLAlignHdg")

With Selection.Find
.Text = " U.S. One 50 lb cartons "
.Replacement.Text = "^pU.S. ONE 50 LB CARTONS"
.Forward = True

.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = "10 lb"
.Replacement.Text = "^p10 LB"
.Forward = True

.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = "20 lb"
.Replacement.Text = "^p20 LB"
.Forward = True

.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Any assistance will be greatly appreciated.

Hoist a stein or two for me!

Phil

"Helmut Weber" wrote:

> Hi Phil,
>
> it's pretty difficult to find anything
> I posted on 2005/07/21 regarding "selection.find",
> as my newsreader shows all dates and times in
> Central European Daylightsavings Time.
> Might be a day's difference to where You are.
>
> >You use the .EXECUTE within the WITH LOOP. The code I have uses either a
> >SELECTION.FIND.EXECUTE or SELECTION.FIND.EXECUTE . . .REPLACE ALL immediately
> >AFTER the END WITH
>
> >What's the difference?
>
> Perhaps only a matter of style.
> Perhaps easier to read, perhaps only to me.
> Perhaps shorter code executes faster, not to say, very likely.
>
> By the way, unless trying to help beginners or programmers
> at an intermediate level, I'm using range instead of selection.
>
> However, having cleared search options ("resetsearch"),
> I find this hard to top according speed and readability:
>
> dim rngDcm as range
> set rngdcm = activedocument.range
> with rngdcm.find
> .text = "Hi"
> while .execute
> ' as long as execution is successfull
> ' no need of "if .found" or "while .found"
> wend
> end with
>
> >Also, can I use IF-THEN-ELSE constructs within the
> >WITH statement depending on certain conditions.
>
> Sure. "Select case" also.
>
> while .execute
> if rngdcm.text = "is" then
> ' ...
> else
> '....
> end if
> ' collapse the range to it's end if you change it's contents
> wend
>
> Need more information to be at your service.
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP, WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>

Re: Helmut Weber -- Info please by Helmut

Helmut
Sat Jul 23 04:39:09 CDT 2005

Hi Phil,

in my humble opinion,

you were trapped by the oddities of VB and VBA,
and maybe it is the same in other MS languages,
where true can be written, in a way, as -1.
msgbox Clng(true) ' -1

When I was using Borland Pascal and other long forgotten languages
like Prolog and Lisp, I think, True was 1 and false was 0.

In addition, using datatype variant throughout instead of
declaring datatypes is not a good idea.

To be more precise, if you use "true" (-1), when calling your sub,
this evaluates to "false" according to your code,
as it is not equal 1!

I reshuffled you code a bit,
used variable names according to my very personal taste,
as you see, they are all 6 characters long, whereby the
first three characters indicate the data type,
and suggest,
to clear search options before calling your sub for the first time,
and resetting options again after calling it for the last time.

Sub SearchReplace( _
strOld As String, strNew As String, _
blnFwd As Boolean, blnFrm As Boolean, _
blnCas As Boolean, blnWrd As Boolean, _
blnAll As Boolean)

With Selection.Find
.Text = strOld
.Replacement.Text = StrNew
.Forward = blnFwd
.Format = blnFrm
.MatchCase = blnCas
.MatchWholeWord = blnWrd
If blnAll Then
.Execute Replace:=wdReplaceAll
Else
.Execute
End If
End With
End Sub
' ---
Sub TestSearchReplace()
ResetSearch
Call SearchReplace("Flesh Seeded", "FLESH SEEDED", -1, -1, -1, -1, -1)
' is the same as
Call SearchReplace("Flesh Seeded", "FLESH SEEDED", True, True, True,
True, True)
ResetSearch
End Sub
' ---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub

Beware of linebreaks by the newsreader.


Greetings from Bavaria,
a region in Europe,
country of BMW, Oktoberfest, Levi Strauss and Alois Alzheimer
lol ;-)

Helmut Weber, MVP, WordVBA

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





Re: Helmut Weber -- Info please by Phil

Phil
Sat Jul 23 11:01:02 CDT 2005

OK,

Let me get this straight -- you lost your car while trying to find your
pants, because you couldn't remember where the beer party was supposed to be?

As I said I inherited a number of these when an employee left on 3 days
notice. I've "dabbled" with Fortran (pre-77), Focal, PL/1, PL/C, RPG II,
Prolog, PASCAL,COBOL, APL, dBase III+ script, SQL, Basic, CBasic, and a
couple of others. Plus, I know about Zone and Fileld Punches AND the
difference between an O29 and a 129.

The ByRef was a quick and dirty way of making something work. I was and am
dealing with a production item that is used 5 days a week, 52 weeks a year.
I can play with a copy all I want, but the MAIN template MUST work. I also,
trew all my careful Variable initialization and testing out the window. One
of those grab a fistful of band-aids and start to patch deals. I never
really have had a chance to sit and think the whole thing through. I have
about 80 macro's that do basically the same thing, but have the same few
lines of code repeated over and over and over. Plus many cases of ADDs,
DELETEs and Changes -- all undocumented, that have occasionally left stray
code hanging around.

Sorry for the rant, just to let you know that I was trained better, but was
given a '62 Beetle that hadn't been cared for and MUST make it work, no
matter how much wire, twine and chewing gum is required. I know a full
re-write is in order.

Thanks for the assist, you'll probably see more postings as I go.

Phil Montgomery

"Helmut Weber" wrote:

> Hi Phil,
>
> in my humble opinion,
>
> you were trapped by the oddities of VB and VBA,
> and maybe it is the same in other MS languages,
> where true can be written, in a way, as -1.
> msgbox Clng(true) ' -1
>
> When I was using Borland Pascal and other long forgotten languages
> like Prolog and Lisp, I think, True was 1 and false was 0.
>
> In addition, using datatype variant throughout instead of
> declaring datatypes is not a good idea.
>
> To be more precise, if you use "true" (-1), when calling your sub,
> this evaluates to "false" according to your code,
> as it is not equal 1!
>
> I reshuffled you code a bit,
> used variable names according to my very personal taste,
> as you see, they are all 6 characters long, whereby the
> first three characters indicate the data type,
> and suggest,
> to clear search options before calling your sub for the first time,
> and resetting options again after calling it for the last time.
>
> Sub SearchReplace( _
> strOld As String, strNew As String, _
> blnFwd As Boolean, blnFrm As Boolean, _
> blnCas As Boolean, blnWrd As Boolean, _
> blnAll As Boolean)
>
> With Selection.Find
> .Text = strOld
> .Replacement.Text = StrNew
> .Forward = blnFwd
> .Format = blnFrm
> .MatchCase = blnCas
> .MatchWholeWord = blnWrd
> If blnAll Then
> .Execute Replace:=wdReplaceAll
> Else
> .Execute
> End If
> End With
> End Sub
> ' ---
> Sub TestSearchReplace()
> ResetSearch
> Call SearchReplace("Flesh Seeded", "FLESH SEEDED", -1, -1, -1, -1, -1)
> ' is the same as
> Call SearchReplace("Flesh Seeded", "FLESH SEEDED", True, True, True,
> True, True)
> ResetSearch
> End Sub
> ' ---
> Public Sub ResetSearch()
> With Selection.Find
> .ClearFormatting
> .Replacement.ClearFormatting
> .Text = ""
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> ' plus some more if needed
> .Execute
> End With
> End Sub
>
> Beware of linebreaks by the newsreader.
>
>
> Greetings from Bavaria,
> a region in Europe,
> country of BMW, Oktoberfest, Levi Strauss and Alois Alzheimer
> lol ;-)
>
> Helmut Weber, MVP, WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>
>
>
>
>

RE: Helmut Weber -- Info please by PhilMontgomery

PhilMontgomery
Mon Jul 25 20:08:01 CDT 2005

Well, I installed your alternate code in one of the Macro's. Seems to be
working ok. Found that I have to be careful of the Sub ResetSearch().
Placing it in one location causes a box to pop up that End Of File has been
reached, do you want to continue at the beginning of the file. Had to click
YES, 48 times before Macro ended.

Give me a #2 and a sheet of paper!


"PhilMontUSDA" wrote:

> I have inherited a number of document template with embedded macro's.
>
> The WITH.SELECTION.FIND code that you posted on 2005/07/21 repeats
> throughout these macro's. We are taking a report that is in multiple
> paragraph form and converting it to tabbed columns, with BOLD, CENTERED
> headings; some paragraph text; certain words BOLD.
>
> Anyway, lots of manipulation of the text. I've done various types of
> programming fo over 35 years -- VBA and I have a severe adversarial
> relationship.
>
> To the point:
>
> You use the .EXECUTE within the WITH LOOP. The code I have uses either a
> SELECTION.FIND.EXECUTE or SELECTION.FIND.EXECUTE . . .REPLACE ALL immediately
> AFTER the END WITH
>
> What's the difference? Also, can I use IF-THEN-ELSE constructs within the
> WITH statement depending on certain conditions.
>
> I'm trying to transform this WITH LOOP into a SUB FINDREPLACE(Param1,
> Param2. . .) construct.
>
> Thanks
>
> Phil Montgomery
>

Re: Helmut Weber -- Info please by Helmut

Helmut
Mon Jul 25 20:55:58 CDT 2005

Hi Phil,

I don't think it comes from "resetsearch".
It comes from "searchreplace". An then it depends
on where the cursor is located when you start the macro.

You could make sure, that the cursor it at the beginning
of the doc and not extended, like this, and in some other ways:

Selection.ExtendMode = False
Selection.StartOf unit:=wdStory

which I assumed as standard.

Or you could change this section of search reaplace:

If blnAll Then
'.Wrap = wdFindContinue ' add this, if it fits your needs
'.Wrap = wdFindStop ' or add this, if that is better for you
.Execute Replace:=wdReplaceAll
Else
.Execute
End If

However, if the cursor is at the doc's start and not extended,
you don't seem to need either one.
So the code would be again a bit shorter
and theoretically a bit faster.

If your search always through the whole doc, the
" else .execute" could be omitted, too.
Otherwise, if you want to search certain ranges,
'.Wrap = wdFindStop ' would be alright.

If you want to decide whether searching all or
the selection or a range, which aren't the whole doc,
or to be precise, a storyrange, you have to introduce
a variable in addition, indicating,
what kind of "wrap" you want.

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

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





Re: Helmut Weber -- Info please by Helmut

Helmut
Mon Jul 25 21:01:43 CDT 2005

Somehow my answer was put in the wrong place...
see above



Re: Helmut Weber -- Info please by PhilMontgomery

PhilMontgomery
Mon Jul 25 22:15:01 CDT 2005

Helmut,

There is a great deal of Greek in all this for me. I've seen code that has
to do with xxStory and a couple of GoTo type commands.

Basically, a group of files are inserted at the End of a document -- cursor
is located with a GoTo "EndOfDoc" bookmark command.

Text is searched for particular words or phrases, Font is changed, Style,
alignment, normal/BOLD, tabs inserted; and some other massaging takes place.
Finished product is then manually checked, cut and pasted into proper
location.

Searching is forward from "EndOfDoc" bookmark, but cursor is bounced to the
beginning of the file with a 'homekey' command; occsionally, the sequence is
HomeKey, then GoTo "EndOfDoc"; generally just searches forward hoping nothing
is in the way.

When all Searching and Replacing is done, the bookmark is moved to the end
of the document.

Personally, I would prefer the cursor to return to the beginning of the
inserted text, not the beginning of the document.

Since I can't see (conceptualize) what the "story" is, I'm not sure where or
what it is. I've got text's up the wazoo, but none really helps.

"Helmut Weber" wrote:

> Hi Phil,
>
> I don't think it comes from "resetsearch".
> It comes from "searchreplace". An then it depends
> on where the cursor is located when you start the macro.
>
> You could make sure, that the cursor it at the beginning
> of the doc and not extended, like this, and in some other ways:
>
> Selection.ExtendMode = False
> Selection.StartOf unit:=wdStory
>
I have NO IDEA what either of these do.


> which I assumed as standard.
>
> Or you could change this section of search reaplace:
>
> If blnAll Then
> '.Wrap = wdFindContinue ' add this, if it fits your needs
> '.Wrap = wdFindStop ' or add this, if that is better for you

I don't know what the 'Wrap' does. Does it jump from EOF to BOF?
(EndOfFile / BeginningOfFile)

> .Execute Replace:=wdReplaceAll
> Else
> .Execute
> End If
>
> However, if the cursor is at the doc's start and not extended,
> you don't seem to need either one.
> So the code would be again a bit shorter
> and theoretically a bit faster.
>
> If your search always through the whole doc, the
> " else .execute" could be omitted, too.
> Otherwise, if you want to search certain ranges,
> '.Wrap = wdFindStop ' would be alright.
>
> If you want to decide whether searching all or
> the selection or a range, which aren't the whole doc,
> or to be precise, a storyrange, you have to introduce
> a variable in addition, indicating,
> what kind of "wrap" you want.
>
Don't know what a "storyrange" is?

> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP, WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>
Greetings from ORlando -- Hurricane Center of Florida!


Re: Helmut Weber -- Info please by Helmut

Helmut
Tue Jul 26 07:39:20 CDT 2005

Hi Phil,
as we need a pragmatic approach, forget about this one:

>Personally, I would prefer the cursor to return to the beginning of the
>inserted text, not the beginning of the document.
Too complicated, maybe some seconds to spare.

>Don't know what a "storyrange" is?

Word documents can be divided in, e.g.
Characters, words, (fuzzy), sentences (fuzzy), paragraphs,
sections, storyranges (headers of some kind, footers of some kind,
frames with text in it). There could be different frames in
different headers, representing different storyranges.
Awful.

E.g. activedocument.range is not all of the doc.
Only the mainstory. The core, so to speak.

>> Selection.ExtendMode = False
>> Selection.StartOf unit:=wdStory
> I have NO IDEA what either of these do.
Switch extendmode off, in case it is on.
Goto the start of document, simplified, regrettably.
It goes to the stary of the story.
Selection.homekey does the same.


According .wrap:
wdFindContinue searches all of the story
wdFindask searches until the end of a range,
and then asks, whether to continue
wdFindstop searches until the end of a range, and stops.

Unable to give a full description.

HTH

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

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



Re: Helmut Weber -- Info please by PhilMontUSDA

PhilMontUSDA
Tue Jul 26 08:16:07 CDT 2005

WHAT was so wrong with WordStar and its .dot commands?

"Helmut Weber" wrote:

> Hi Phil,
> as we need a pragmatic approach, forget about this one:
>
> >Personally, I would prefer the cursor to return to the beginning of the
> >inserted text, not the beginning of the document.
> Too complicated, maybe some seconds to spare.
>
> >Don't know what a "storyrange" is?
>
> Word documents can be divided in, e.g.
> Characters, words, (fuzzy), sentences (fuzzy), paragraphs,
> sections, storyranges (headers of some kind, footers of some kind,
> frames with text in it). There could be different frames in
> different headers, representing different storyranges.
> Awful.
>
> E.g. activedocument.range is not all of the doc.
> Only the mainstory. The core, so to speak.
>
> >> Selection.ExtendMode = False
> >> Selection.StartOf unit:=wdStory
> > I have NO IDEA what either of these do.
> Switch extendmode off, in case it is on.
> Goto the start of document, simplified, regrettably.
> It goes to the stary of the story.
> Selection.homekey does the same.
>
>
> According .wrap:
> wdFindContinue searches all of the story
> wdFindask searches until the end of a range,
> and then asks, whether to continue
> wdFindstop searches until the end of a range, and stops.
>
> Unable to give a full description.
>
> HTH
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP, WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>
>
>

Re: Helmut Weber -- Info please by Helmut

Helmut
Tue Jul 26 14:23:01 CDT 2005

Hi Phil,

>WHAT was so wrong with WordStar and its .dot commands?

bad marketing, no feeling for the business,
maybe just bad luck. Wordstar was # 1 and vanished.

"Happens", as I comment desastrous moves in chess,
most often my moves. ;-)

I liked "Electric Pencil". Ever heard of?

>I would prefer the cursor to return to the beginning of the
>inserted text, not the beginning of the document.

No need of selection and cursor at all!

Define a range: Dim rTmp As Range
Initialize it: Set rTmp = ActiveDocument.Range
Set it's start to the end: rTmp.Start = rTmp.End

Insert the new file at the range "rTmp":
rTmp.InsertFile FileName:="c:\test\word\FindReplace.doc"

Expand rTmp to the document's end.
rTmp.End = ActiveDocument.Range.End
rTmp is encompassing the inserted document.

Restrict search and replace to the so defined range rTmp:

Sub SearchReplaceInRange( _
rngNow As Range, _
strOld As String, StrNew As String, _
blnFrm As Boolean, _
blnCas As Boolean, blnWrd As Boolean)

With rngNow.Find
.Text = strOld
.Replacement.Text = StrNew
.Format = blnFrm
.Wrap = wdFindStop
.MatchCase = blnCas
.MatchWholeWord = blnWrd
.Execute Replace:=wdReplaceAll
End With
End Sub
' ---------------------------------------
Sub TestSearchReplaceInRange()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
rTmp.Start = rTmp.End
rTmp.InsertFile FileName:="c:\test\word\FindReplace.doc"
rTmp.End = ActiveDocument.Range.End
ResetSearch
SearchReplaceInRange rTmp, "e", "E", True, True, True
ResetSearch
End Sub

Getting clearer?

Gruß

Helmut Weber, MVP, WordVBA

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



Re: Helmut Weber -- Info please by Helmut

Helmut
Tue Jul 26 14:36:26 CDT 2005

... :-(

F*, F*, F*,

SearchReplaceInRange rTmp, "e", "E", True, True, True

replacing single letters and matchwholeword = true
doesn't make much sense.

For single letters:
SearchReplaceInRange rTmp, "e", "E", True, True, false

Helmut





Re: Helmut Weber -- Info please by PhilMontUSDA

PhilMontUSDA
Tue Jul 26 14:52:06 CDT 2005

Hi Helmut,

I do remember the name Electric Pencil. Never used it. That reminds me,
one programming language I didn't mention -- 8080 Assembly, assembled and
compiled with M80.com in a CP/M environment.

I am curious to know if there is any relation between WordStar and
StarOffice. Haven't seen the latter so I have no idea. Wordstar died in the
U.S. Government with Reagan, he brought in a number of private sector folks
that lived an died with WordPerfect. Next migration was when MicroSoft
bundled Office with WIndows for Government purchases.

I also miss Banyan Vines!

Haven't had much chance to work on my macro issues. Just a busy day and it
is not an "official" task, so I can only work on it when something stops or
someone in DC wants a change. Then it becomes critical and you know who is
the only person that can fix it.

Well, need to get t the griindstone. Still have a report to finish.

Phil Montgomery

"Helmut Weber" wrote:

> Hi Phil,
>
> >WHAT was so wrong with WordStar and its .dot commands?
>
> bad marketing, no feeling for the business,
> maybe just bad luck. Wordstar was # 1 and vanished.
>
> "Happens", as I comment desastrous moves in chess,
> most often my moves. ;-)
>
> I liked "Electric Pencil". Ever heard of?
>
> >I would prefer the cursor to return to the beginning of the
> >inserted text, not the beginning of the document.
>
> No need of selection and cursor at all!
>
> Define a range: Dim rTmp As Range
> Initialize it: Set rTmp = ActiveDocument.Range
> Set it's start to the end: rTmp.Start = rTmp.End
>
> Insert the new file at the range "rTmp":
> rTmp.InsertFile FileName:="c:\test\word\FindReplace.doc"
>
> Expand rTmp to the document's end.
> rTmp.End = ActiveDocument.Range.End
> rTmp is encompassing the inserted document.
>
> Restrict search and replace to the so defined range rTmp:
>
> Sub SearchReplaceInRange( _
> rngNow As Range, _
> strOld As String, StrNew As String, _
> blnFrm As Boolean, _
> blnCas As Boolean, blnWrd As Boolean)
>
> With rngNow.Find
> .Text = strOld
> .Replacement.Text = StrNew
> .Format = blnFrm
> .Wrap = wdFindStop
> .MatchCase = blnCas
> .MatchWholeWord = blnWrd
> .Execute Replace:=wdReplaceAll
> End With
> End Sub
> ' ---------------------------------------
> Sub TestSearchReplaceInRange()
> Dim rTmp As Range
> Set rTmp = ActiveDocument.Range
> rTmp.Start = rTmp.End
> rTmp.InsertFile FileName:="c:\test\word\FindReplace.doc"
> rTmp.End = ActiveDocument.Range.End
> ResetSearch
> SearchReplaceInRange rTmp, "e", "E", True, True, True
> ResetSearch
> End Sub
>
> Getting clearer?
>
> GruÃ?
>
> Helmut Weber, MVP, WordVBA
>
> "red.sys" & chr$(64) & "t-online.de"
> Win XP, Office 2003
>
>
>