none
How to set a table cell margin RRS feed

  • Question

  • There are padding properties for table cell, aslo it can be done through tablestyle object. I can't find anything that sets table cell margin, any ideas? Thanks.
    Wednesday, June 1, 2011 2:44 PM

Answers

  • I understood padding to mean cell margin but maybe you are referring to spacing between cells?

    Here is VBA code that identifes the properties.

      ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed
      With Selection.Tables(1)
        If .Style <> "Table Grid" Then
          .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
      End With
      With Selection.Tables(1)
        .TopPadding = InchesToPoints(0.03)
        .BottomPadding = InchesToPoints(0.03)
        .LeftPadding = InchesToPoints(0.11)
        .RightPadding = InchesToPoints(0.11)
        .Spacing = InchesToPoints(0.04)
        .AllowPageBreaks = True
        .AllowAutoFit = True
      End With
    
    

    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by feg2008 Monday, June 6, 2011 3:55 PM
    Wednesday, June 1, 2011 4:50 PM

All replies

  • I understood padding to mean cell margin but maybe you are referring to spacing between cells?

    Here is VBA code that identifes the properties.

      ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed
      With Selection.Tables(1)
        If .Style <> "Table Grid" Then
          .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
      End With
      With Selection.Tables(1)
        .TopPadding = InchesToPoints(0.03)
        .BottomPadding = InchesToPoints(0.03)
        .LeftPadding = InchesToPoints(0.11)
        .RightPadding = InchesToPoints(0.11)
        .Spacing = InchesToPoints(0.04)
        .AllowPageBreaks = True
        .AllowAutoFit = True
      End With
    
    

    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by feg2008 Monday, June 6, 2011 3:55 PM
    Wednesday, June 1, 2011 4:50 PM
  • Hi Rich,

    Thanks for your suggestions.

    What I try to do is that inserting a table in a cell of outer table such that there is no any white spaces between the border of inserted inner table and the cell containing the inner table. Any ideas on how to do this? thanks.

    Wednesday, June 1, 2011 10:11 PM
  • If I understand correctly, you want to take a single cell in a multi-cell table and change its padding to zero. 

    You can do that but it effects, in some manner, all other cells in the table.  If you change the left or right padding in a single cell, it effects the column width of all other adajcent columns.  If you change the top or bottom padding of a single cell it effects all cells in the same row.

    Further, once you change these setting in a single cell, you cannot alter the padding settings for a row or column. An individual cell's custom margin settings take precedence for the row/column.


    Kind Regards, Rich ... http://greatcirclelearning.com
    Wednesday, June 1, 2011 11:09 PM
  • Hi feg2008,

    Any update? Does the information provided by Rich helpful?


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 3, 2011 7:43 AM
    Moderator
  • It is nice to know information provided by Rich. However, I still want to try it out in my application by setting margins of table cells to zero.

    I can do this manually in Word via Table Properties... -> Cell tab -> Options... which brings up the cell margins form where I can set the margins properties. Any ideas on how to do this using Word sdk? Thanks.

    Friday, June 3, 2011 8:08 PM
  • Try something along the lines of:

    Sub Demo()
    Dim Tbl As Table, sRwHt As Single, StrRowCol As String
    With ActiveDocument.Tables(1).Cell(2, 2)
      StrRowCol = InputBox("How many Rows & Columns?" & vbCr & _
        "in Row#,Column# format, please.")
      .TopPadding = 0
      .BottomPadding = 0
      .LeftPadding = 0
      .RightPadding = 0
      sRwHt = .Height
      Set Tbl = .Tables.Add(Range:=.Range, NumRows:=1, NumColumns:=1)
      With Tbl
        .Rows(1).Height = sRwHt
        .TopPadding = 0
        .BottomPadding = 0
        .LeftPadding = 0
        .RightPadding = 0
        .Spacing = 0
        .Cell(1, 1).Split NumRows:=Trim(Split(StrRowCol, ",")(0)), _
          NumColumns:=Trim(Split(StrRowCol, ",")(1))
      End With
    End With
    End Sub

    The above macro inserts a new table into cell B2 in the first table in the document. It solicits the # rows and columns for the new table. Theoretically, you should be able to plug those values into the .Tables.Add expression but, on my system at least, the # rows value is ignored; hence the .Cell(1, 1).Split expression.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Friday, June 3, 2011 11:01 PM
  • I think Word SDK cell Padding properties are used to set the cell Margins(Table Properties... -> Cell tab -> Options... which brings up the cell margins form where I can set the margins properties) in Word.
    Monday, June 6, 2011 3:57 PM