Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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 |
#4
![]() |
|||
|
|||
![]()
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 |
#5
![]() |
|||
|
|||
![]()
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 |
#6
![]() |
|||
|
|||
![]()
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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Table cell alignments | Microsoft Word Help | |||
word table cell resize or word table cell size change or word table change cell size | Tables | |||
Table Cell not Centered Correctly (Too far left) | New Users | |||
Insertion point after section break | Microsoft Word Help | |||
Indenting a bullet list in a table cell. | Tables |