Row cursor position in Word via VBA

K

kenshiro2000

Hi,

How can I get row number at the Cursor position in VBA Word XP?

Thanks

ken
 
H

Helmut Weber

Hi,

you're probably meaning the line number on a page.

MsgBox Selection.Information(wdFirstCharacterLineNumber)

You may have to switch views beforehand.
Normal to printlayout and back or vice versa.

Otherwise, the msgbox may return -1.


--
Gruß

Helmut Weber, MVP WordVBA

"red.sys" & chr$(64) & "t-online.de"
Win XP, Office 2003
 
K

kenshiro2000

Thanks so much.....

But Now I have another problem....

wdFirstCharacterLineNumber return the character at the right of
collapsed Selection....so How can I know when the return is the Line
number and when is the character code????

This is a strange behavior!!!

Thanks

Helmut Weber ha scritto:
 
H

Helmut Weber

Hi,
wdFirstCharacterLineNumber return the character at the right of
collapsed Selection..

hmm...

indeed, very strange.
Never heard this before, and hard to believe.

Show us your code.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

kenshiro2000

This is from the Help:

"wdFirstCharacterLineNumber Returns the character position of the first
character in the specified selection or range. If the selection or
range is collapsed, the character number immediately to the right of
the range or selection is returned (this is the same as the character
line number displayed in the status bar after "Ln")."

Bye
 
H

Helmut Weber

Hi,
If the selection or range is collapsed, the character number immediately
to the right of the range or selection is returned

this is simply wrong.

It should read as:
"The line number where the character immediately to the right is..."

And this wrong, too.

Because, if you move the insertion point to the end of a line,
e.g. Selection.EndKey Unit:=wdLine
where there is no character at all immediately to the right,
you still get the line the insertion point is in.

If one thinks of "immediately to the right" as equal to "next",
then the help is wrong again.

Happens.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

kenshiro2000

I have tested this and it is TRUE :)

In a blank line, the System.Information return vbCr not the row number.
 
D

Doug Robbins - Word MVP

MsgBox Selection.Information(wdFirstCharacterLineNumber)

displays the line number for me regardless of the state of the selection.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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