none
apply all borders to all cells in a table VBA RRS feed

  • Question

  • Hi

    I want to apply all borders to all cells in a table. The best I have been able to do is apply a single border to the entire table. See the code below.

    .Range.Cells.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
    .Range.Cells.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
    .Range.Cells.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
    .Range.Cells.Borders(wdBorderTop).LineStyle = wdLineStyleSingle

    I was hoping to get away from using a fixed for loop. Anyideas thanks

    Thursday, January 17, 2013 3:10 AM

Answers

  • Try something like

        With ActiveDocument.Tables(1)
            .Borders(wdBorderTop).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
            .Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle
            .Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
        End With


    Regards, Hans Vogelaar

    • Marked as answer by tfitzhardinge Friday, January 18, 2013 2:42 AM
    Thursday, January 17, 2013 7:18 AM