A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Get current column/row index



 
 
Thread Tools Display Modes
  #1  
Old October 22nd, 2008, 06:08 PM posted to microsoft.public.word.tables
dmpollock
external usenet poster
 
Posts: 2
Default Get current column/row index

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
  #2  
Old October 22nd, 2008, 06:54 PM posted to microsoft.public.word.tables
Jay Freedman
external usenet poster
 
Posts: 9,488
Default Get current column/row index

dmpollock wrote:
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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.


  #3  
Old October 22nd, 2008, 07:48 PM posted to microsoft.public.word.tables
dmpollock
external usenet poster
 
Posts: 2
Default Get current column/row index

This was perfect.

Thanks much.

"Jay Freedman" wrote:

dmpollock wrote:
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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.