problem with Find property in Word 2003

J

Jens-Erik

Hi

I have a problem with Find property in Word 2003. This works well

in Word 2000. The problem is when the last text is found and

replaced, then it start to go in a loop and insert the replaced

text over and over again on the same place.



The procedure (see example) search and replace (translate)

word/string repeatedly through the document. If Parameter 1 is

TRUE then text becomes bold. If Parameter 2 is TRUE then call

procedure DateRemove (Delete other text in the same paragraph)

Parameter 3 is text that will be replaced with Parameter 4. The

procedure is called from several points.



I hope someone can help me to make this Word 2003 compatible.



Thanks

Jens-Erik



Example:

....

Call RepeatedlySearch(True, False, "Postadresse: ", _

"Postal address: ")

....



Private Sub RepeatedlySearch(blnBoldText As Boolean, _

blnRemoveDate As Boolean, strSearchString As String, _

strReplaceText As String)



With Selection

.HomeKey Unit:=wdStory

..Find.Execute Findtext:=strSearchString, _

Forward:=True, Wrap:=wdFindStop

While .Find.Found = True

.Text = strReplaceText

If blnBoldText = True Then .Range.Bold = True

If blnRemoveDate = True Then

DateRemove

End If

Selection.MoveDown Unit:=wdLine, Extend:=wdMove

WordBasic.repeatFind

Wend

End With



End Sub ' RepeatedlySearch

----------------
 
H

Helmut Weber

Hi Jens-Erik,
I don't know what's wrong with your code,
but I think it is the wordbasic command.
It is high time to abandon wordbasic.
Have a look at this:
---
Sub RepeatedlySearch(blnBoldText As Boolean, _
blnRemoveDate As Boolean, strSearchString As String, _
strReplaceText As String)
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = strSearchString
.Replacement.Text = strReplaceText
While .Execute
' oRng.Select for testing
If blnBoldText = True Then oRng.Bold = True
If blnRemoveDate = True Then oRng.Delete ' thought so
oRng.Start = oRng.End
oRng.End = ActiveDocument.Content.End
Wend
End With
End Sub
---
Sub Test387()
Call RepeatedlySearch(True, False, _
"Postadresse: ", _
"Postal address: ")
End Sub
 
H

herman

Helmut, Thank you very much.

I have to insert the line "oRng.Text = strReplaceText " in the .Execute
loop then all worked well.

Jens-Erik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top