TableSort

Syntax

TableSort [.DontSortHdr = number] [, .FieldNum = number] [, .Type = number] [.Order = number] [, .FieldNum2 = number] [, .Type2 = number] [, .Order2 = number] [, .FieldNum3 = number] [, .Type3 = number] [, .Order3 = number] [, .Separator = number] [, .SortColumn = number] [, .CaseSensitive = number]

Remarks

Sorts the selected paragraphs or table rows. If you want to sort paragraphs within a table cell, select only the paragraphs and not the end-of-cell mark; if you select the end-of-cell mark and then sort, Word displays a message stating that it found no valid records to sort. The arguments for the TableSort statement correspond to the options in the Sort dialog box (Table menu).

Argument

Explanation

.DontSortHdr

If 1, excludes the first paragraph or table row from the sort operation.

.FieldNum, .FieldNum2, .FieldNum3

The number of the fields (text or table columns) to sort by. Word sorts by .FieldNum, then by .FieldNum2, and then by .FieldNum3.

.Type, .Type2, .Type3

The respective sort types for .FieldNum, .FieldNum2, and .FieldNum3:

0 (zero) Alphanumeric

1 Numeric

2 Date

.Order, .Order2, .Order3

The sorting order to use when sorting .FieldNum, .FieldNum2, and .FieldNum3:

0 (zero) Ascending

1 Descending

.Separator

The type of separator (irrelevant for table rows):

0 (zero) Comma

1 Tab

2 Other (the character that appears in the Other box in the Sort Options dialog box)

.SortColumn

If 1, sorts only the selected column (requires a column selection).

.CaseSensitive

If 1, sorts with case sensitivity.


Example

This example sorts table rows in ascending alphanumeric order, first by the first column, and then by the second column. The first row is excluded from the sort operation.


Select Case SelInfo(15)
    Case -1
        MsgBox "Please place the insertion point in a table."
    Case 1
        MsgBox "Sorry, can't sort a single-row table."
    Case Else
        TableSelectTable
        TableSort .Order = 0, .FieldNum = "1", .Type = 0, \
                .Order2 = 0, .FieldNum2 = "2", .Type2 = 0, \
                .DontSortHdr = 1
End Select

The following illustration shows a table before and after sorting by the preceding example.

See Also

TableSortAToZ, TableSortZToA