How to get table row height in Word

I looked everywhere and tried different things. This was supposed to be impossible. So I'm going to try here and see if anyone else had any luck.

Is there a way to get the row height of a table in Word if the row is HeightRuleset to wdRowHeightAuto?

Alternatively, if there is a way to get the height of the cell, I agree with it as a solution, since you can calculate the height of the row by finding the largest cell.

+3
source share
3 answers

How about cheating?

Dim tbl As Word.Table
Dim r As Row
Dim c As Cell

Set tbl = ActiveDocument.Tables(1)

For Each r In tbl.Rows
    iHeight = r.HeightRule
    r.HeightRule = 1
    Debug.Print r.Height
    r.HeightRule = iHeight
Next
+1
source

You can find the row height using Range.Information (). The following snippet does not work for the last row in the table or the last row on the page

Dim Tbl as Table
Dim RowNo as Integer
Dim RowHeight as Double

' set Tbl and RowNo to the table and row number you want to measure

RowHeight=Tbl.Rows(RowNo+1).Range.Information(wdVerticalPositionRelativeToPage) _
    - Tbl.Rows(RowNo).Range.Information(wdVerticalPositionRelativeToPage)

, .

, , 0. ( , .)

Dim Doc As Document
Dim Tbl As Table

Dim Pos As Long
Dim RowNo As Integer
Dim ColNo As Integer
Dim CellHeight As Single

' set Doc, Tbl, RowNo and Colno to the document,table and row number you want to
' measure or provide a cell range if you prefer

Pos = Tbl.Cell(RowNo, ColNo).Range.End - 1 ' last character in cell

CellHeight = Doc.Range(Pos, Pos).Information(wdVerticalPositionRelativeToTextBoundary)
+3

, HeightRule , - "" , , .

, , , para :

Set r = c.Row
With r
   If .HeightRule <> wdRowHeightExactly Then
        .HeightRule = wdRowHeightExactly
         Set p = c.Range.ParagraphFormat
         .Height = c.BottomPadding + c.TopPadding + p.SpaceBefore + p.SpaceAfter +        p.LineSpacing
    End If
End With
+1

Source: https://habr.com/ru/post/1784176/


All Articles