How can I locate a paragraph using the .find method ?

J

Jamie Carper

The following code tells me if the searched text exists:

Dim FoundText as Boolean

With ActiveDocument.Range.Find
FoundText = .Execute("The text I am searching for")
End With

How can I extract the exact paragraph object where this text is found?

I do not wish to manipulate the text, merely goto the location as if this
were a bookmark.
 
D

Dave Lett

Hi Jamie,

The easiest way to extract the text might be to simply select it using the
selection object instead of the Range object, as in the following:

Dim FoundText As Boolean
Dim sExtractText as String

With Selection.Find
FoundText = .Execute("The text I am searching for")
End With

sExtractText = Selection.Text

HTH,
Dave
 
J

Jonathan West

Jamie Carper said:
The following code tells me if the searched text exists:

Dim FoundText as Boolean

With ActiveDocument.Range.Find
FoundText = .Execute("The text I am searching for")
End With

How can I extract the exact paragraph object where this text is found?

I do not wish to manipulate the text, merely goto the location as if this
were a bookmark.

Do this

ActiveDocument.Range.Select
Selection.Find.Execute "The text I am searching for"
 
J

Jamie Carper

I think I was too hasty posting this query.

Here is the solution:

Dim FoundText as Boolean
Dim FoundTextParagraph as Paragraph

With ActiveDocument.Range.Find
FoundText = .Execute("The text I am searching for")
Set FoundTextParagraph = .Parent.Paragraphs(1)
End With
 

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