Reply
 
Thread Tools Display Modes
  #1   Report Post  
Ed
 
Posts: n/a
Default Identify table cell with insertion point in VBA?

Is there a way using VBA to identify the column and row of the Word table
cell containing the insertion point, or that has been selected? (An
equivalent to Excel's ActiveCell)

Ed


  #2   Report Post  
Jean-Guy Marcil
 
Posts: n/a
Default

Ed was telling us:
Ed nous racontait que :

Is there a way using VBA to identify the column and row of the Word
table cell containing the insertion point, or that has been selected?
(An equivalent to Excel's ActiveCell)


Try the following. Note that if you are dealing with tables containing
merged cells, then it will not work.

'_______________________________________
Dim IndexCol As Long
Dim IndexRow As Long


With Selection
If Not .Information(wdWithInTable) Then
MsgBox "Selection must be in a table cell.", _
vbCritical, "Invalid Selection"
Exit Sub
Else
IndexCol = .Columns(1).Index
IndexRow = .Rows(1).Index
MsgBox "The coordinates of the top left cell of " _
& "the current selection is row " & IndexRow _
& " and column " & IndexCol & ".", _
vbInformation, "Active Cell"
End If
End With
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
ISTOO
Word MVP site:
http://www.word.mvps.org



  #3   Report Post  
Greg Maxey
 
Posts: n/a
Default

Ed,

Try something like:

Sub IDCell()
Dim oCol As Single
Dim oRow As Single

oCol = Selection.Information(wdStartOfRangeColumnNumber)
oRow = Selection.Information(wdStartOfRangeRowNumber)
MsgBox ("The IP is located in column " & oCol & ", row " & oRow & ".")



End Sub

--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Ed wrote:
Is there a way using VBA to identify the column and row of the Word
table cell containing the insertion point, or that has been selected?
(An equivalent to Excel's ActiveCell)

Ed



  #4   Report Post  
Ed
 
Posts: n/a
Default

Thank you, Greg!
"Greg Maxey" wrote in message
...
Ed,

Try something like:

Sub IDCell()
Dim oCol As Single
Dim oRow As Single

oCol = Selection.Information(wdStartOfRangeColumnNumber)
oRow = Selection.Information(wdStartOfRangeRowNumber)
MsgBox ("The IP is located in column " & oCol & ", row " & oRow & ".")



End Sub

--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Ed wrote:
Is there a way using VBA to identify the column and row of the Word
table cell containing the insertion point, or that has been selected?
(An equivalent to Excel's ActiveCell)

Ed





  #5   Report Post  
Ed
 
Posts: n/a
Default

Thank you! I never expected to get 3 different ways to do the same thing!

"Jean-Guy Marcil" wrote in message
...
Ed was telling us:
Ed nous racontait que :

Is there a way using VBA to identify the column and row of the Word
table cell containing the insertion point, or that has been selected?
(An equivalent to Excel's ActiveCell)


Try the following. Note that if you are dealing with tables containing
merged cells, then it will not work.

'_______________________________________
Dim IndexCol As Long
Dim IndexRow As Long


With Selection
If Not .Information(wdWithInTable) Then
MsgBox "Selection must be in a table cell.", _
vbCritical, "Invalid Selection"
Exit Sub
Else
IndexCol = .Columns(1).Index
IndexRow = .Rows(1).Index
MsgBox "The coordinates of the top left cell of " _
& "the current selection is row " & IndexRow _
& " and column " & IndexCol & ".", _
vbInformation, "Active Cell"
End If
End With
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
ISTOO
Word MVP site:
http://www.word.mvps.org







  #6   Report Post  
Jean-Guy Marcil
 
Posts: n/a
Default

Ed was telling us:
Ed nous racontait que :

Thank you! I never expected to get 3 different ways to do the same
thing!


In fact, 2 ways... Greg and Helmut's ways are the same, it is just that Greg
wrapped it up in a more complete sub.

My fault, I forgot about
Selection.Information(wdEndOfRangeRowNumber)
which is not bothered by merged cells (But you still have to consider that
in your code, unless you know for a fact that the table cannot contain
merged cells).

Also, remember that if many cells are selected,
Selection.Information(wdEndOfRangeRowNumber)
gives you the bottom right cell index, my clumsier method gives you the top
left cell.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
ISTOO
Word MVP site:
http://www.word.mvps.org



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table cell alignments Kevin Microsoft Word Help 5 January 18th 05 12:41 AM
word table cell resize or word table cell size change or word table change cell size [email protected] Tables 0 January 13th 05 10:55 PM
Table Cell not Centered Correctly (Too far left) Peter Reaper New Users 7 January 13th 05 06:54 PM
Insertion point after section break Sherry Microsoft Word Help 4 January 12th 05 02:57 AM
Indenting a bullet list in a table cell. Fred Holmes Tables 1 October 27th 04 05:17 PM


All times are GMT +1. The time now is 03:21 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"