O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Split Method

The Split method applies to (among others) the Cell object, the Cells collection object, and the Table object. For a Cell object, the syntax is:

CellObject.Split(NumRows, NumColumns)

This will split the cell into multiple cells. For a Cells collection, the syntax is:

CellsObject.Split(NumRows, NumColumns, MergeBeforeSplit)

In this case, the method splits a range of cells. Finally, for the Table object, the syntax is:

TableObject.Split(BeforeRow)

In this case, the method inserts an empty paragraph immediately above the specified row in the table, thus splitting the table in two. The Split method returns a Table object that denotes the lower table. For example, assuming that the insertion point lies within the list of column object members earlier in this chapter, the code:

	Dim tbl As Table
	Dim tbl2 As Table
	Selection.Expand wdTable    ' Select table
	Set tbl = Selection.Tables(1)
	Set tbl2 = tbl.Split(3)

turns that table into two tables, as shown in Figure 16-2.

A table split into two parts

Figure 16-2. A table split into two parts

The various parameters of the Split method are:

NumColumns

The number of columns that the cell or group of cells is to be split into.

NumRows

The number of rows that the cell or group of cells is to be split into.

MergeBeforeSplit

Set to True to merge the cells with one another before splitting them.

BeforeRow

The row at which the table is split. This row becomes part of the lower ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required