Get current column/row index

D

dmpollock

I am writing a macro to enter text into a table. How can I get the current
column and row number where the cursor is in the table?

thanks
 
J

Jay Freedman

dmpollock said:
I am writing a macro to enter text into a table. How can I get the
current column and row number where the cursor is in the table?

thanks

Use the .Information property of the Selection object with the appropriate
constants:

Selection.Information(wdEndOfRangeColumnNumber)
Selection.Information(wdEndOfRangeRowNumber)

If the selection is extended and contains more than one cell, the numbers
returned refer to the location of the end of the selection. If you think
that might be the situation, and you want the location of the beginning of
the selection, you can do something like this:

Dim myRg As Range
Set myRg = Selection.Range
MyRg.Collapse Direction:=wdCollapseStart
MyRow = MyRg.Information(wdEndOfRangeRowNumber)

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
D

dmpollock

This was perfect.

Thanks much.

Jay Freedman said:
Use the .Information property of the Selection object with the appropriate
constants:

Selection.Information(wdEndOfRangeColumnNumber)
Selection.Information(wdEndOfRangeRowNumber)

If the selection is extended and contains more than one cell, the numbers
returned refer to the location of the end of the selection. If you think
that might be the situation, and you want the location of the beginning of
the selection, you can do something like this:

Dim myRg As Range
Set myRg = Selection.Range
MyRg.Collapse Direction:=wdCollapseStart
MyRow = MyRg.Information(wdEndOfRangeRowNumber)

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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