Cursor position, line number

A

Aidil

Does anyone knows how to obtain the cursor line position...

This code doesn't work for me... it returns rare numbers
but not the cursor actual position.
Selection.Information(wdVerticalPositionRelativeToPage)
or
Selection.Information
(wdVerticalPositionRelativeToTextBoundary)

I'd be grateful for any help...

Thanks
-Aidil
 
D

Dave Lett

Hi Aidil,

In your first post, you mentioned that you want the line number

Dim oRng As Range
Set oRng = ActiveDocument.Range _
(Start:=ActiveDocument.Range.Start, _
End:=Selection.Range.End)
MsgBox "The insertion point is on line " &
oRng.ComputeStatistics(wdStatisticLines)

If you want the _cursor_, not the insertion point (blinking line where text
will appear if you start typing), then I'm afraid that I cannot assist you.

HTH
 
D

Doug Robbins - Word MVP

Hi Aidil,

Use:

Dim oRng As Range, i As Integer, j As Integer
Set oRng = ActiveDocument.Range _
(Start:=ActiveDocument.Range.Start, _
End:=Selection.Range.End)
i = oRng.ComputeStatistics(wdStatisticLines)
oRng.End = ActiveDocument.Bookmarks("\page").Range.Start
j = oRng.ComputeStatistics(wdStatisticLines)
MsgBox "The selection is in line " & i - j & " of the current page."

This does not however work reliably if the selection is in a table or if
there is a table on the page and the selection is after that page.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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