jumpjack
03-15-2012, 03:13 AM
I have a table several pages long.
Is it possibile to determine on which row, relative to a PAGE, the selection is located?
This code can only determine position relative to the beginning of the table:
Option Explicit
Sub SelectionInfo()
'
Dim iSelectionRowEnd As Integer
Dim iSelectionRowStart As Integer
Dim iSelectionColumnEnd As Integer
Dim iSelectionColumnStart As Integer
Dim lngStart As Long
Dim lngEnd As Long
' Check if Selection IS in a table
' if not, exit Sub after message
If Selection.Information(wdWithInTable) = False Then
MsgBox "Selection is not in a table. Exiting macro."
Else
lngStart = Selection.Range.Start
lngEnd = Selection.Range.End
' get the numbers for the END of the selection range
iSelectionRowEnd = Selection.Information(wdEndOfRangeRowNumber)
iSelectionColumnEnd = Selection.Information(wdEndOfRangeColumnNumber)
' collapse the selection range
Selection.Collapse Direction:=wdCollapseStart
' get the numbers for the END of the selection range
' now of course the START of the previous selection
iSelectionRowStart = Selection.Information(wdEndOfRangeRowNumber)
iSelectionColumnStart = Selection.Information(wdEndOfRangeColumnNumber)
' RESELECT the same range
Selection.MoveEnd Unit:=wdCharacter, Count:=lngEnd - lngStart
' display the range of cells covered by the selection
MsgBox "The selection covers " & Selection.Cells.Count & " cells, from Cell(" & _
iSelectionRowStart & "," & iSelectionColumnStart & ") to Cell(" & _
iSelectionRowEnd & "," & iSelectionColumnEnd & ")."
End If
End Sub
Is it possibile to determine on which row, relative to a PAGE, the selection is located?
This code can only determine position relative to the beginning of the table:
Option Explicit
Sub SelectionInfo()
'
Dim iSelectionRowEnd As Integer
Dim iSelectionRowStart As Integer
Dim iSelectionColumnEnd As Integer
Dim iSelectionColumnStart As Integer
Dim lngStart As Long
Dim lngEnd As Long
' Check if Selection IS in a table
' if not, exit Sub after message
If Selection.Information(wdWithInTable) = False Then
MsgBox "Selection is not in a table. Exiting macro."
Else
lngStart = Selection.Range.Start
lngEnd = Selection.Range.End
' get the numbers for the END of the selection range
iSelectionRowEnd = Selection.Information(wdEndOfRangeRowNumber)
iSelectionColumnEnd = Selection.Information(wdEndOfRangeColumnNumber)
' collapse the selection range
Selection.Collapse Direction:=wdCollapseStart
' get the numbers for the END of the selection range
' now of course the START of the previous selection
iSelectionRowStart = Selection.Information(wdEndOfRangeRowNumber)
iSelectionColumnStart = Selection.Information(wdEndOfRangeColumnNumber)
' RESELECT the same range
Selection.MoveEnd Unit:=wdCharacter, Count:=lngEnd - lngStart
' display the range of cells covered by the selection
MsgBox "The selection covers " & Selection.Cells.Count & " cells, from Cell(" & _
iSelectionRowStart & "," & iSelectionColumnStart & ") to Cell(" & _
iSelectionRowEnd & "," & iSelectionColumnEnd & ")."
End If
End Sub