Macro for table width? RRS feed

  • Question

  • I know how to record a basic macro. Now I want to create a very simple one to set the width of a table, but after I select the table and do Record Macro, it won't let me get to Table Properties to do what I want. ???
    Sunday, February 19, 2012 12:19 AM


  • In Word 2010, I can place the insertion point in the table while recording a macro, activate the Layout tab of the ribbon, and click Properties in the Table group.

    The recorded macro looks like this:

    Sub SetTableWidth()
    ' SetTableWidth Macro
        Selection.Tables(1).PreferredWidthType = wdPreferredWidthPoints
        Selection.Tables(1).PreferredWidth = CentimetersToPoints(10)
    End Sub

    (I set the width to 10 cm)

    You can edit this to make it slightly more elegant:

    Sub SetTableWidth()
        With Selection.Tables(1)
            .PreferredWidthType = wdPreferredWidthPoints
            .PreferredWidth = CentimetersToPoints(10)
        End With
    End Sub

    Perhaps you can use this as starting point.

    Regards, Hans Vogelaar

    Sunday, February 19, 2012 1:47 AM