Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Get current paragraph

291 views
Skip to first unread message

Helmut Weber

unread,
Mar 27, 2009, 8:24:14 AM3/27/09
to
Hi Danny,

see:
http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Graham Mayor

unread,
Mar 27, 2009, 8:37:55 AM3/27/09
to
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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Danny wrote:
> 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


0 new messages