Paste VBA help

A

Alan

If this sounds like a beginner question please forgive me, but alas, I
am a beginner. What I need to do is copy a bit of text in one document,
open another document, then search for that text there.
Everything works find except the actual pasting of the text into the
find dialog box. after creating a macro this is what I get.

Sub Macro1()

Selection.Find.ClearFormatting
With Selection.Find
.Text = "sample"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub

Is there something I substitute ".Text = "sample"" for that would paste
a selection instesd of static text into this box? I noticed that most
times that simply copying text will automatically place that text into
the box, but not always.(???) I have a suspicion that the answer lies in
a DIM statement but I've never used these. If someone could show me an
example of that I would much appreciative(and I could stop puling my
hair out) Tia Alan
 
J

Jezebel

You're on the wrong track with pasting. What you need to do is read the text
from the first document into a variable, then use that variable in the
subsequent find.

Dim pText as string

:
pText = Doc1.Range .... (however you're finding the text in the
first place)
:

With Doc2.Content.Find
.Clearformatting
.Text = pText
:
 

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