Word VBA: Adding a Row Below the Last Row of a Selected Table

This Word VBA macro adds a row below the last row of a selected table.

Macro Example

Sub AddRowBelowLast()

  Selection.Tables(1).Rows.Add

End Sub

Description

[Application.]Selection

  Selection...

The [Application.]Selection property returns the Selection object that represents a selected range on a Word document.

obj-Word-Application-Selection

Because the Selection property is a member of the Word.Global class, we can omit the Application property.

obj-Word-Global-Selection

Selection.Tables

  Selection.Tables...

The Selection.Tables property returns a Tables collection object in a selected range.

obj-Word-Selection-Tables

Tables(1) (Tables.Item(1))

  Selection.Tables(1)...

The Tables.Item method returns an individual Table object in the Tables collection object. And the Tables.Item(1) represents the first table.

obj-Word-Tables-Item

The Item method is a default member of the Tables collection object. We can see a little blue marble beside its icon in the Object Browser.
So we can omit the .Item.

Tables(1).Rows (Table.Rows)

  Selection.Tables(1).Rows...

The Tables(1).Rows (Table.Rows property) returns a Rows collection object that represents all the table rows within a table.

obj-Word-Table-Rows

Rows.Add

  Selection.Tables(1).Rows.Add

We can add a new row after the last row of the table by the Rows.Add method.

obj-Word-Rows-Add

Sub AddRowBelowLast()

  Selection.Tables(1).Rows.Add

End Sub

Properties

http://www.relief.jp/itnote/archives/word-vba-adding-row-above-or-below-last-row.php

Apply To

  • Word 2013
  • Word 2010
  • Word 2007