Re: Find and replace tabs
From: Peter Hewett (nospam_at_xtra.co.nz)
Date: 05/31/04
- Next message: Peter Hewett: "Re: Search through all rows in a named table"
- Previous message: Howard Kaikow: "Re: code to do a brute force algorithm?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 01 Jun 2004 10:25:43 +1200
Hi Larry
Sometimes the Find object can behave strangely (not as you would expect). This has been
attributed to ghost properties from a previous S+R operation. So if you specify *every*
Property you know the object is correctly initialised. This is one of the standard bits
of code I pulled from my library:
Public Sub SearchAndReplaceInStory(ByVal rngStory As Word.Range, _
ByVal strSearch As String, _
ByVal strReplace As String)
Do Until (rngStory Is Nothing)
With rngStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = strSearch
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Set rngStory = rngStory.NextStoryRange
Loop
End Sub
As you can see it sets a few more properties.
HTH + Cheers - Peter
"Larry" <larry328@att.net>, said:
>Hi Peter,
>
>You know more about this than I do, but have you ever searched for a tab
>and not gotten a tab? Have you ever replaced found text by X and ended
>up replacing it by Y?
>
>So I'm interested: where does the possible ambiguity come in to a S&R?
>
>Larry
>
>
>
>
>"Peter Hewett" <nospam@xtra.co.nz> wrote in message
>news:r7dp901h77aqf3qiob5s8vni5vl8jk7ica@4ax.com...
>> Hi Larry
>>
>> If you want consistent reliable results when using th Find object I've
>found it prudent to
>> initialise it thoroughly. What's a few lines of code? I also think
>that it makes exactly
>> what you're searching for/replacing unambiguous.
>>
>> HTH + Cheers - Peter
>>
>>
>> "Larry" <larry328@att.net>, said:
>>
>> >Isn't a simple find and replace enough?
>> >
>> >Dim r As Range
>> >Set r = Selection.Range
>> >
>> > With r.Find
>> > .ClearFormatting
>> > .Replacement.ClearFormatting
>> > .Text = "^t"
>> > .Replacement.Text = ""
>> > .MatchWildcards = False
>> > .Forward = True
>> > .Wrap = wdFindContinue
>> > End With
>> > r.Find.Execute Replace:=wdReplaceAll
>> >
>>
>
- Next message: Peter Hewett: "Re: Search through all rows in a named table"
- Previous message: Howard Kaikow: "Re: code to do a brute force algorithm?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|