Get current paragraph

D

Danny

I've been using "Selection.Find" to find a certain word.
I want to know in which paragraph that word is found, and I don't know how
to do this.
I can access the "First", "Last" paragraphs because that are properties I
found.
How can I get the "Current" paragraph?

Thanks
 
G

Graham Mayor

What do you want to do with the paragraph, having found it? In the following
example, sPara is the paragraph containing the found expression.

Sub FindPara()
Dim rPara As Range
Dim sFind As String
sFind = "Text to find"
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=sFind, _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
Set rPara = Selection.Paragraphs(1).Range
'Do what you want with the paragraph range eg
MsgBox rPara
Exit Sub 'If you want to find only the first occurrence
Loop
End With
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Danny

Hi Helmut, Graham,

Thanks foor your help.
It did resolve my problem.

I searched for a certain keyword in my document, and I searched for a second
keyword. Then, I had to change Paragraph settings for the paragraphs in
between.

Regards,

Danny
 

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