Using the attached file example, I need to determine any given cell vertical position relative to the page. In the case of the cell at row 6, column 1 (not vertically merged - but others in the row are, column 1, 2 and 12), I would expect the following code to produce a position slightly higher than the 1 inch header (72 points), when in fact , it produces a value of 97.5:
Option Explicit
Public myTable As Table
Public myRange As Range
Public myCell As Cell
Public myPosition6 As Variant
Public myHeight6 As Variant
Sub CellPosition()
Set myTable = ActiveDocument.Tables(1)
Set myCell = myTable.Cell(6, 3)
myCell.HeightRule = wdRowHeightExactly
myHeight6 = myCell.Height
myCell.Select
Selection.MoveEnd unit:=wdRow, Count:=1 'Put cursor outside of Table
Selection.Collapse Direction:=wdCollapseEnd
Set myRange = Selection.Range
myPosition6 = myRange.Information(wdVerticalPositionRelativeToPage)
End Sub
The 97.5 seems to be at the bottom of the row and not the cell top edge (97.5 - 23.7 cell height = 73.8 slightly greater than the 1 inch header). Instead of putting the cursor outside the table row, keeping the range inside the cell produces a value of 79:
Option Explicit
Public myTable As Table
Public myRange As Range
Public myCell As Cell
Public myPosition6 As Variant
Public myHeight6 As Variant
Sub CellPosition()
Set myTable = ActiveDocument.Tables(1)
Set myCell = myTable.Cell(6, 3)
myCell.HeightRule = wdRowHeightExactly
myHeight6 = myCell.Height
myCell.Range.Select
Selection.Collapse Direction:=wdCollapseEnd
Set myRange = Selection.Range
myPosition6 = myRange.Information(wdVerticalPositionRelativeToPage)
End Sub
The 79 value is closer but inspection of the table by double clicking the header shows row 6 right at the 72 point header demarcation line. Anyone see an error in the approach here?
Thanks!