Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get line number

Status
Not open for further replies.

GP1

Programmer
Jan 15, 2002
23
0
0
NO
Hi,
Can anyone please tell me how to get the line number the cursor is curently at when coding for MS Word.

Thanks,
Gavin
 
GP1,

Use the Information property of the Selection object. Try the following procedure to see how this works:

Code:
Sub CursorPosition()
Dim Row As Variant
Dim Col As Variant
Dim Page As Variant
Dim msg As String

Row = ActiveWindow.Selection.Information(wdFirstCharacterLineNumber)
Col = ActiveWindow.Selection.Information(wdFirstCharacterColumnNumber)
Page = ActiveWindow.Selection.Information(wdActiveEndPageNumber)
msg = "Column = " & Col & vbCrLf & "Line = " & Row _
& vbCrLf & "Page = " & Page
MsgBox msg, vbInformation + vbOKOnly, "Cursor Position"

End Sub

Paste it into a code module. Type some stuff in a document window, then run the procedure. This should get you started.

Btw, the Information property returns a wealth of, well, information. Check it out in the online Help.

Regards,
M. Smith
 
Hey,
I mailed to tell you thankyou very much for the idea you gave. I was able to use row number to great efect in writing the code. It was a life saver. Thanks again,

Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top