2 Attachment(s)
Find table cell border bottom vertical position relative to the page
I want to select the row 2, column 4 table cell and find its border bottom vertical position relative to the page. Is there a way to do this using the wdBorderBottom property?
This example code gets me close. I put my cursor at the end of the text in the cell and then add in the font size and bottom padding. There are complicating issues (see attached file).Attachment 30908
Code:
Sub TableCellPosition()
'This subroutine calculates the position (in points) of the cell bottom border
Dim oTable As Table
Dim oCell As Cell
Dim oFS, oCBP, oCBBP As Variant
Set oTable = ActiveDocument.Tables(1)
Set oCell = oTable.Cell(1, 4)
oCell.Select
Selection.MoveEnd Unit:=wdCharacter, Count:=-1 'Put cursor at end of cell text selection
Selection.Collapse Direction:=wdCollapseEnd
'Possibilities within selected cell could include no text, single or multiple lines of text; text vertical alignment at top, middle or bottom, cell bottom margin padding, text font size, cell height rule. All of these parameters give different results.
Set myRange = Selection.Range 'pick up current cursor position at end of text
oFS = Selection.Font.Size ‘Font size
oCBP = ActiveDocument.Tables(n).BottomPadding ‘Cell Bottom Padding
oCBBP = Selection.Information(wdVerticalPositionRelativeToPage) + oFS + oCBP
End Sub
My cell height rule is set to “AtLeast”. Setting it to “Exactly” cuts off the second line in the row. Adding in oCell.height instead of font size and bottom padding ignores the gap caused by taller cells in the row if the single line of text in the selected cell is aligned in the center. I’m looking to avoid these complications with text alignment or number of lines if there is another way (such as the cell border bottom?). Or do I set the selected cell text to align bottom, perform the calculations, then put the alignment back to what it was originally?