Sort Method Example

This example creates a 5x5 table in a new document, inserts text into each cell, and then sorts the table in descending alphanumeric order.

Set newDoc = Documents.Add 
Set myTable = newDoc.Tables.Add(Selection.Range, 5, 5)
For iRow = 1 To myTable.Rows.Count
    For iCol = 1 To myTable.Columns.Count
        Set myRange= myTable.Rows(iRow).Cells(iCol).Range
        myRange.InsertAfter "Cell (" & Str$(iRow) _
            & "," & Str$(iCol) & ")"
    Next iCol
Next iRow
MsgBox "Click OK to sort in descending order."
myTable.Sort SortOrder:=wdSortOrderDescending

This example inserts three lines of text into a new document and then sorts the lines in ascending alphanumeric order.

Set newDoc = Documents.Add 
newDoc.Content.InsertAfter "pear" & Chr(13) _
    & "zucchini" & Chr(13) _
    & "apple" & Chr(13)
newDoc.Content.Sort SortOrder:=wdSortOrderAscending