Determine Line Numbers of a Selection?

S

subbob

Problem: How to determine range of line numbers for the active
selection within a Word document using a macro?

The document has line numbering turned on from beginning to end.

Multiple people are editing the same document. For ease of comparison,
we are using page numbers & line numbers to reference our comments.

The page number of the active selection is determined using:

Selection.Information(wdActiveEndPageNumber)

Is there a way to determine the range of line numbers of the active
selection?

For example, in the text below (numbered 31 to 39 for example
purposes). Assume that the phrase "the glare will distress him, and
he will be unable to see the realities of which in his former state he
had seen the shadows; and then conceive some one saying to him, that
what he saw before was an illusion" was selected.

The macro needs to return 33 & 35 - the beginning and ending line of
the selection.

31 And now look again, and see what will naturally follow it' the
prisoners are released and disabused of their error.
32 At first, when any of them is liberated and compelled suddenly to
stand up and turn his neck round and walk and
33 look towards the light, he will suffer sharp pains; the glare will
distress him, and he will be unable to see the
34 realities of which in his former state he had seen the shadows; and
then conceive some one saying to him, that
35 what he saw before was an illusion, but that now, when he is
approaching nearer to being and his eye is turned
36 towards more real existence, he has a clearer vision, -what will be
his reply? And you may further imagine that
37 his instructor is pointing to the objects as they pass and
requiring him to name them, -will he not be perplexed?
38 Will he not fancy that the shadows which he formerly saw are truer
than the objects which are now shown to
39 him?
 
P

Pesach Shelnitz

Hi,

The following macro shows the range of line numbers for a selection. Note
that this macro assumes that the selection is all on the same page.

Sub ShowLineNumberRange()
Dim myRange As Range

With Selection
Set myRange = .Range
myRange.Collapse Direction:=wdCollapseEnd
MsgBox "The selected text includes lines " & _
.Information(wdFirstCharacterLineNumber) _
& " to " & _
myRange.Information(wdFirstCharacterLineNumber) _
& "."
End With
End Sub
 

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