1 Attachment(s)
Example Table for Cell position w/vertically merged cells
Thanks for the quick response. Being a newbie, I'm still learning this forum. I haven't discovered how to paste a table with the cell lines showing in this window, so used your direction to attach my Word example document. Since the first post of this thread, I have tried moving the cursor from the cell to the end of the row and outside of the table since I'm mainly interested in the vertical position of the row. I get more sensical results but not all that accurate:
Example for finding vertical page position of cell (row 6, col 3):
Code:
Dim myTable As Table
Dim myCell As Cell
Dim myPosition As Integer
Set myTable = ActiveDocument.Tables(1)
Set myCell = myTable.Cell(6, 3)
myCell.Range.Select
Selection.MoveEnd unit:=wdRow, Count:=1
Selection.Collapse Direction:=wdCollapseEnd 'Place cursor outside Table (in margin area)
Set myRange = Selection.Range 'pick up current cursor position (merged cells will mess up position inquiry otherwise)
myPosition = myRange.Information(wdVerticalPositionRelativeToPage)
The Header is 1 inch (72 points), so I am expecting myPosition (of the 6th row) to be a little bit larger than 72 but it comes back as 95.5
How can I get this closer to my expectations?
Thanks for any recommendations!
2 Attachment(s)
More on cell vertical position relative to page
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:
Code:
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:
Code:
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!