Thanks for your reply. It might be in part for curiosity, but mainly for the
desire to write clean "one-liners" (wish more comedy shows would do that,
ha-ha). I was hoping for something along the lines of the Selection.Move
function with the "Count:=" option.
You wrote "c = long, counter"--I'm assuming that that would be like the
following in concept:
For c=1 to 20
Find [text]
Next c
How would you use a range with this? I think I know but I'm wondering if you
will complete the code. I'm more tied into using Selection.Find since, as I
mentioned in a comment that should be posting soon, I find searching with
ranges to be a lot slower, at least with my bigger projects where I'm
processing through a lot of data.
Hi Bryan,
>You wrote "c = long, counter"--I'm assuming that that would be like the
>following in concept:
[quoted text clipped - 4 lines]
>
>How would you use a range with this?
>I think I know but I'm wondering if you will complete the code.
' ------------------------------------------------------------
Sub MyReplace(r As Range, a As String, b As String, c As Long)
If c = 0 Then Exit Sub
Dim t As Long
Dim w As Range
t = 0
c = c - 1
Set w = r.Duplicate
With w.Find
.Text = a
.Replacement.Text = b
While .Execute(Replace:=wdReplaceOne) _
And t < c And w.InRange(r)
t = t + 1
w.start = w.End
w.End = r.End + 1
Wend
End With
End Sub
' ------------------------------------------------
Sub Test45689()
MyReplace Selection.Range, "x", "y", 10
End Sub
' ------------------------------------------------
>I'm more tied into using Selection.Find since, as I
>mentioned in a comment that should be posting soon, I find searching with
>ranges to be a lot slower, at least with my bigger projects where I'm
>processing through a lot of data.
Range is usually much slower in tables than the selection.
Google for my decent name and "ranges", "table".
Factor 50 sometimes.
Also, as far as I see,
there is hardly a difference in speed between
range and selection, if the selection is the whole doc,
or, if the selection is the insertion point at the start of doc.
HTH

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"