none
2010 Word Table Row Height Issue RRS feed

  • Question

  • Hello:

    Setting the row height in a Word table seems to be problematic.  If I set it at an exact height, then it will not wrap text if the text exceeds the length of the cell.

    If I change the setting to "At Least", then the row height is much too tall, regardless of the height value I enter.  Is there a way to set it at an exact height but still allow a cell to expand to show all the text?

    I think I tried every combination.  The "At Least" setting creates rows that are much too tall and spread out.  All the vertical cell borders are set to zero.

    Ideas?

    Regards,


    Rich Locus, Logicwurks, LLC

    http://www.logicwurks.com

    Monday, April 21, 2014 3:09 PM

Answers

  • In the lines

    objTable.Rows.HeightRule = wdRowHeightAuto
    objTable.Rows.Height = 0.23 * 72

    you first set the height to automatic, but then negate that by setting the height to a specific amount. You should remove the line

    objTable.Rows.Height = 0.23 * 72

    and only keep

    objTable.Rows.HeightRule = wdRowHeightAuto

    If the rows are still too tall, it is probably due to the paragraph formatting of the text in the cells: the paragraphs may have Spacing Before or Spacing After set to a positive amount, and/or Line spacing may be set to a different value than Single.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by RichLocus Monday, April 21, 2014 11:05 PM
    Monday, April 21, 2014 10:38 PM
  • Hans:

    That was it.  All I had to do was add three statements to the code and all the empty space went away... see the last 3 statements.

    For i = 1 To intNoOfRows
         For j = 1 To intNoOfColumns
            objTable.Cell(i, j).Range.Text = wksDataToTransfer.Cells(i, j).Value
         Next j
    Next i
    
    Set objRange = objTable.Range
    objRange.ParagraphFormat.SpaceBefore = 0
    objRange.ParagraphFormat.SpaceAfter = 0
    

    Thanks again!!


    Rich Locus, Logicwurks, LLC

    http://www.logicwurks.com

    Monday, April 21, 2014 11:42 PM

All replies

  • I think you need to set the HeightRule property of the rows to wdRowHeightAuto instead of to wdRowHeightExactly or wdRowHeightAtLeast.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, April 21, 2014 6:51 PM
  • Hans:

    Thanks so much for taking your time to answer.  I tried the wdRowHeightAuto and it still came out with very high rows.  I have included samples of the three settings.

    The first is the wdRowHeightExactly, which has the spacing I want but refuses to expand cells, even when I set that property to expand.

    The second is the wdRowHeightAuto... See how it still adds too much space.

    The third is the wdRowHeightAtLeast... Same problem with rows that are too high.

    Here's a sample of the code for the wdRowHeightAuto:

    intNoOfRows = 26
    intNoOfColumns = 2
    Set objRange = objDoc.GoTo(What:=wdGoToBookmark, Name:="FirstBookmark")
    objDoc.Tables.Add objRange, intNoOfRows, intNoOfColumns
    Set objTable = objDoc.Tables(1)
    objTable.Columns(1).Width = 2 * 72
    objTable.Columns(2).Width = 4.5 * 72
    objTable.Rows.HeightRule = wdRowHeightAuto
    objTable.Rows.Height = 0.23 * 72
    objTable.Borders.Enable = False
    
    objWord.Options.DefaultBorderLineWidth = wdLineWidth150pt
    objWord.Options.DefaultBorderColor = -704610049
    
    With objTable.Borders(wdBorderTop)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Borders(wdBorderLeft)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Borders(wdBorderBottom)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Borders(wdBorderRight)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Rows(1).Borders(wdBorderBottom)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    For i = 1 To intNoOfRows
         For j = 1 To intNoOfColumns
            objTable.Cell(i, j).Range.Text = wksDataToTransfer.Cells(i, j).Value
         Next j
    Next i
    

    Thanks,


    Rich Locus, Logicwurks, LLC

    http://www.logicwurks.com

    Monday, April 21, 2014 9:56 PM
  • In the lines

    objTable.Rows.HeightRule = wdRowHeightAuto
    objTable.Rows.Height = 0.23 * 72

    you first set the height to automatic, but then negate that by setting the height to a specific amount. You should remove the line

    objTable.Rows.Height = 0.23 * 72

    and only keep

    objTable.Rows.HeightRule = wdRowHeightAuto

    If the rows are still too tall, it is probably due to the paragraph formatting of the text in the cells: the paragraphs may have Spacing Before or Spacing After set to a positive amount, and/or Line spacing may be set to a different value than Single.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by RichLocus Monday, April 21, 2014 11:05 PM
    Monday, April 21, 2014 10:38 PM
  • Hans:

    Thanks!  I did remove the one statement and the rows were still too high.  I think you called it when you mentioned the line spacing.  I will adjust that and it should work.

    ' *******************************************************
    ' Locate A BookMark And Insert A Table After The Bookmark
    ' *******************************************************
    intNoOfRows = 26
    intNoOfColumns = 2
    Set objRange = objDoc.GoTo(What:=wdGoToBookmark, Name:="FirstBookmark")
    objDoc.Tables.Add objRange, intNoOfRows, intNoOfColumns
    Set objTable = objDoc.Tables(1)
    objTable.Columns(1).Width = 2 * 72
    objTable.Columns(2).Width = 4.5 * 72
    objTable.Rows.HeightRule = wdRowHeightAuto
    objTable.Borders.Enable = False
    
    objWord.Options.DefaultBorderLineWidth = wdLineWidth150pt
    objWord.Options.DefaultBorderColor = -704610049
    
    With objTable.Borders(wdBorderTop)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Borders(wdBorderLeft)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Borders(wdBorderBottom)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Borders(wdBorderRight)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    With objTable.Rows(1).Borders(wdBorderBottom)
        .LineStyle = objWord.Options.DefaultBorderLineStyle
        .LineWidth = objWord.Options.DefaultBorderLineWidth
        .Color = objWord.Options.DefaultBorderColor
    End With
    
    intNoOfRows = 26
    intNoOfColumns = 2

    Regards,


    Rich Locus, Logicwurks, LLC

    http://www.logicwurks.com

    Monday, April 21, 2014 11:07 PM
  • Hans:

    That was it.  All I had to do was add three statements to the code and all the empty space went away... see the last 3 statements.

    For i = 1 To intNoOfRows
         For j = 1 To intNoOfColumns
            objTable.Cell(i, j).Range.Text = wksDataToTransfer.Cells(i, j).Value
         Next j
    Next i
    
    Set objRange = objTable.Range
    objRange.ParagraphFormat.SpaceBefore = 0
    objRange.ParagraphFormat.SpaceAfter = 0
    

    Thanks again!!


    Rich Locus, Logicwurks, LLC

    http://www.logicwurks.com

    Monday, April 21, 2014 11:42 PM