Consulting

Results 1 to 1 of 1

Thread: Find table cell border bottom vertical position relative to the page

  1. #1
    VBAX Regular jfdawson's Avatar
    Joined
    Jan 2023
    Location
    Birmingham
    Posts
    7
    Location

    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).

    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?
    Attached Files Attached Files
    Last edited by Aussiebear; 06-29-2023 at 04:07 PM. Reason: edited the ghastly green code to normal for readability issues

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •