Hi,

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

Thanks

ken

Re: Row cursor position in Word via VBA by Helmut

Helmut
Thu Jan 19 10:05:21 CST 2006

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


Re: Row cursor position in Word via VBA by kenshiro2000

kenshiro2000
Fri Jan 20 08:32:36 CST 2006

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:

> 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=DF
>
> Helmut Weber, MVP WordVBA
>=20
> "red.sys" & chr$(64) & "t-online.de"
> Win XP, Office 2003


Re: Row cursor position in Word via VBA by Helmut

Helmut
Fri Jan 20 15:12:49 CST 2006

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"




Re: Row cursor position in Word via VBA by kenshiro2000

kenshiro2000
Wed Jan 25 03:29:34 CST 2006

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


Re: Row cursor position in Word via VBA by Helmut

Helmut
Wed Jan 25 09:56:27 CST 2006

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"

Re: Row cursor position in Word via VBA by kenshiro2000

kenshiro2000
Wed Jan 25 11:15:30 CST 2006

I have tested this and it is TRUE :-)

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


Re: Row cursor position in Word via VBA by Doug

Doug
Wed Jan 25 23:20:55 CST 2006

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

"kenshiro2000" <kenshiro2000@libero.it> wrote in message
news:1138209330.928679.45710@z14g2000cwz.googlegroups.com...
>I have tested this and it is TRUE :-)
>
> In a blank line, the System.Information return vbCr not the row number.
>