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

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

Macro Example

Sub AddRowBelowLast()

  Selection.Tables(1).Rows.Last.Select
  Selection.InsertRowsBelow

End Sub

Description

Selecting the Last Row

Sub...

  Selection.Tables(1).Rows.Last.Select

The 3rd line selects the last row of a current table.

[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.Last

  Selection.Tables(1).Rows.Last

The Rows.Last property returns the Row object that represents the last row

Last.Select (Row.Select)

  Selection.Tables(1).Rows.Last.Select

The Last.Select (Row.Select method) selects the last row.

Inserts Row

Sub...

  Selection.Tables(1).Rows.Last.Select
  Selection.InsertRowsBelow

Selection.InsertRowsBelow

The Selection.InsertRowsBelow method inserts a row below the current selection.

Sub AddRowBelowLast()

  Selection.Tables(1).Rows.Last.Select
  Selection.InsertRowsBelow

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