Share via

VBA Word Table - Adding borders

Anonymous
2014-04-25T10:13:16+00:00

I have used the following VBA code to create a table in a Word document ...

Dim oCell As Word.Range

Dim oTable As Word.Table

Set oTable = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=2, NumColumns:=2)

Set oCell = oTable.Cell(1, 1).Range

oCell.End = oCell.End - 1

oCell.Fields.Add oCell, Type:=wdFieldDocVariable, Text:="""Name01""", PreserveFormatting:=False

This works OK.

How do I place borders around the cells and set the font to be Arial size 10?

Thanks in anticipation.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2014-04-25T11:48:19+00:00

Add this code to your macro:

    With oTable.Borders

        .InsideColor = wdColorAutomatic

        .InsideLineStyle = wdLineStyleSingle

        .OutsideColor = wdColorAutomatic

        .OutsideLineStyle = wdLineStyleSingle

    End With

    With oTable.Range.Font

        .Name = "Arial"

        .Size = 10

    End With

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2014-04-25T12:14:02+00:00

    Thank you.

    Was this answer helpful?

    0 comments No comments