Current Paragraph

B

BillCPA

If you have selected a range in the activedocument, is there a way to know
the paragraph number (in relation to the whole document) that the selected
range is in?

If not, is there a simple way to move from the current paragraph to the
start (or end) of the previous paragraph? Or the succeeding paragraph?
 
G

Greg Maxey

Sub ScratchMaco()
Dim oRng As Word.Range
Set oRng = Selection.Range
MsgBox ActiveDocument.Range(0,
oRng.Paragraphs(1).Range.End).Paragraphs.Count
'Move to the start of the next paragraph
Selection.MoveDown wdParagraph, 1
'Move to the start of the preceding paragraph
Selection.MoveUp wdParagraph, 1
End Sub


If you have selected a range in the activedocument, is there a way to
know the paragraph number (in relation to the whole document) that
the selected range is in?

If not, is there a simple way to move from the current paragraph to
the start (or end) of the previous paragraph? Or the succeeding
paragraph?

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 
S

StevenM

To: Greg Maxey,

Re: MsgBox ActiveDocument.Range(0, _
oRng.Paragraphs(1).Range.End).Paragraphs.Count

The highest number I'm getting is 4. It seems to work for the first few
paragraphs, and then after that every paragraph appears to return the number
4. Am I doing something wrong? Does it work for you?

Steven Craig Miller
 
G

Greg Maxey

Steven,

I haven't performed comprehensive testing (just on a half page of gibberish)
but is seems to work. It certainly doesn't get hung up on 4.

Sub ScratchMaco()
Dim oRng As Word.Range
Set oRng = Selection.Range
MsgBox ActiveDocument.Range(0,
oRng.Paragraphs(1).Range.End).Paragraphs.Count
End Sub

To: Greg Maxey,

Re: MsgBox ActiveDocument.Range(0, _
oRng.Paragraphs(1).Range.End).Paragraphs.Count

The highest number I'm getting is 4. It seems to work for the first
few paragraphs, and then after that every paragraph appears to return
the number
4. Am I doing something wrong? Does it work for you?

Steven Craig Miller

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 
S

StevenM

To: Greg,

I found my mistake. <sigh> The document I was testing it on had used
vertical line feeds rather than paragraph marks. Egg on my face.

Steven Craig Miller
 

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