[posted and emailed]
Terry,
As you may have figured out, even if this code worked, crawling
through a document one word at a time is impossibly slow. See
my earlier post for a solution to this question. But since you're
obviously trying very hard, here are some general tips for your
next attempt at using any of these VBA elements:
These lines:
Set myrange = .Words(x)
If myrange = ThisDocument.TextBox1.Text Then
will give Word a headache. You've defined myrange as a variant
but its first usage assigns it to a Words object (which is a
range). So you'll never be able to test to see if it equals
a the .Text expression (which is a string, not a range).
This line:
myrange.Range.Paragraph.Copy
Will befuddle it even more since you're trying to apply the
..Range property to a range. But the bigger error here is
that .Paragraph is not a property of Range. What you would
have wanted here (if you were gonna try & use this code, which
ya aren't, eh?) was
myrange.Paragraphs(1).Range.Copy
The .Paragraphs(1) means the first (here the only) paragraph
that myrange includes or touches.
In this line:
myrange.MoveUntil Cset:=ThisDocument.TextBox1.Text
The CSet doesn't give the range a *string* to find and move to.
It gives a set of characters, and the range will move until it
finds ANY of those characters. For example, if you have the
sentence:
Joan ate Frank's shoe.
and you begin with myrange at the beginning of the sentence,
the line:
myrange.MoveUntil CSet:="Frank"
will *not* move the range to the word 'Frank'; instead it will
move it to the 'a' in Joan, because that's the first character
it'll find that's among the characters F, r, a, n, or k.
And finally,
[document object].Content.Paste
would just overwrite the entire content of your document with
what you're pasting. You actually want to *append* the paragraph
you found. See my other post.
One thing that would help you a lot as you wade through VBA is
to be sure Auto List Members is checked (in Tools> Options>
Editor) (click that from the VBA editor, not from Word). That
gives you a clickable list of all the methods & properties that
are allowed to complete the line you're coding, as soon as you
press the period after the last element you entered. If it's
not on the list, you can't use it there. This would've flagged
the blooper at myrange.Range.Paragraph.Copy.
Hope this helps.