none
Getting actual height of table cell RRS feed

  • Question

  • Hello!
    I've stuck into a little problem during performing my task.
    My issue was to count how many pages one column occupies and to copy the text from that column to each page it occupies. I can not use headers, because there is already duplicated header in my document. So, I decided to count the length of the column and separate the column into several columns. But here was the problem. The field Cell.Height or Row[i].Height returns 99999 (undefined) if Height Rule is "Automatic", always returns 12 if Height Rule is At Least. So, I can not get the actual height of any column. In Word I saw one field, which I need - Table Tools -> Layout -> Height. This field shows the actual height and width of any cell. Is there any way to get the value from this field? 
    Wednesday, November 22, 2017 6:25 AM

Answers

  • Have you tried using a table header row?

    In any event, rather than the actual height, you probably need to know only how many pages the column spans, then split the column into that many rows - whose cell height on each page you then need to set so the bottom margin is at the page break.


    Cheers
    Paul Edstein
    [MS MVP - Word]


    Wednesday, November 22, 2017 8:18 AM

All replies

  • Have you tried using a table header row?

    In any event, rather than the actual height, you probably need to know only how many pages the column spans, then split the column into that many rows - whose cell height on each page you then need to set so the bottom margin is at the page break.


    Cheers
    Paul Edstein
    [MS MVP - Word]


    Wednesday, November 22, 2017 8:18 AM
  • Thanks for quick reply! 

    Finally I have found the solution. Now I am using this operation to get the number of pages for selected block.
    app.Selection.Information[WdInformation.wdActiveEndAdjustedPageNumber];

    Thank you for help.
    Wednesday, November 22, 2017 11:56 AM
  • Do be aware that splitting the cell and adjusting the row heights is unreliable; as soon as you open the document on a system using a different printer driver, Word's optimisation of the page layout to suit the new printer may result in your breaks being somewhere other than at the page boundaries.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, November 22, 2017 9:40 PM
  • Thanks, now I have one question about enumerations. 
    I have written some code: 
    for (int i = 2; i <= table.Rows.Count; i++) {
                    table.Cell(i, 6).Select();
                    pageEnd = app.Selection.Information[WdInformation.wdActiveEndPageNumber];
    ...
    }
    In MSDN is written that "wdActiveEndPageNumber returns the number of the page that contains the active end of the specified selection or range, counting from the beginning of the document." So, if my column starts at the 1st page and ends at the 6th page, I thought that the pageEnd variable will be 6, but it is 1 if a column is located on exactly one page and 2 if a column takes more than one page. Maybe I'm wrond in understanding the meanings of enum members.
    Friday, November 24, 2017 7:52 AM
  • Try something based on:

    Sub Demo()
    Dim i As Long, j As Long
    With ActiveDocument.Tables(1).Range
      i = .Cells(1).Range.Characters.First.Information(wdActiveEndPageNumber)
      j = .Cells(.Cells.Count).Range.Characters.First.Information(wdActiveEndPageNumber)
    End With
    MsgBox "The table starts on page " & i & " and ends on page " & j
    End Sub

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, November 24, 2017 11:54 PM