Finding the current line and column location of the cursor

B

bbacklin

Hi,

I need the VBA code to find the line number and column location of th
cursor when someone is typing in a word document. I would also like t
do the same for a bookmark.

Bra
 
G

Greg

Sub Test()
MsgBox Selection.Information(wdFirstCharacterLineNumber)
MsgBox Selection.Information(wdFirstCharacterColumnNumber)
End Sub

"Do the same for a bookmark?" What does than mean?
 
B

bbacklin

Hi Greg,

Thanks for answer #1. That works great.

I wanted to find the line number for the beginning of a bookmarke
section and the end of a bookmarked section. I suppose that I coul
use the same command you suggested but set the range first at th
begining of the bookmark section and then to the end.

Bra
 
G

Greg Maxey

Brad,

Close. I think I get what you want to do now. Try:

Sub Test1()
Dim oBkm As Range
Set oBkm = ActiveDocument.Bookmarks("Test").Range
MsgBox oBkm.Information(wdFirstCharacterLineNumber)
MsgBox oBkm.Characters.Last.Information(wdFirstCharacterLineNumber)
End Sub

-
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
 

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