Selection.Sort Method

Word Developer Reference

Sorts the paragraphs in the specified selection.

Syntax

expression.Sort(ExcludeHeader, FieldNumber, SortFieldType, SortOrder, FieldNumber2, SortFieldType2, SortOrder2, FieldNumber3, SortFieldType3, SortOrder3, SortColumn, Separator, CaseSensitive, BidiSort, IgnoreThe, IgnoreKashida, IgnoreDiacritics, IgnoreHe, LanguageID, SubFieldNumber, SubFieldNumber2, SubFieldNumber3)

expression   Required. A variable that represents a Selection object.

Parameters

Name Required/Optional Data Type Description
ExcludeHeader Optional Variant True to exclude the first row or paragraph header from the sort operation. The default value is False.
FieldNumber Optional Variant The first field by which to sort.
SortFieldType Optional Variant The sort type for FieldNumber. Can be one of the WdSortFieldType constants. The default value is wdSortFieldAlphanumeric. Some of the WdSortFieldType constants may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.
SortOrder Optional Variant The sorting order to use when sorting FieldNumber. Can be one WdSortOrder constant.The default value is wdSortOrderAscending.
FieldNumber2 Optional Variant The second field by which to sort.
SortFieldType2 Optional Variant The sort type for FieldNumber2. Can be one of the WdSortFieldType constants. The default value is wdSortFieldAlphanumeric. Some of the WdSortFieldType constants may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.
SortOrder Optional Variant The sorting order to use when sorting FieldNumber2. Can be one WdSortOrder constant.The default value is wdSortOrderAscending.
SortColumn2 Optional Variant True to sort only the column specified by the Selection object.
Separator Optional Variant The type of field separator.
FieldNumber3 Optional Variant The third field by which to sort.
SortFieldType3 Optional Variant The sort type for FieldNumber3. Can be one of the WdSortFieldType constants. The default value is wdSortFieldAlphanumeric. Some of the WdSortFieldType constants may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.
SortOrder3 Optional Variant The sorting order to use when sorting FieldNumber3. Can be one WdSortOrder constant.The default value is wdSortOrderAscending.
CaseSensitive Optional Variant True to sort with case sensitivity. The default value is False.
BidiSort Optional Variant True to sort based on right-to-left language rules. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
IgnoreThe Optional Variant True to ignore the Arabic character alef lam when sorting right-to-left language text. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
IgnoreKashida Optional Variant True to ignore kashidas when sorting right-to-left language text. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
IgnoreDiacritics Optional Variant True to ignore bidirectional control characters when sorting right-to-left language text. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
IgnoreHe Optional Variant True to ignore the Hebrew character he when sorting right-to-left language text. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
LanguageID Optional Variant Specifies the sorting language. Can be one of the WdLanguageID constants.
SubFieldNumber Optional Variant A secondary field number by which to sort.
SubFieldNumber2 Optional Variant A secondary field number by which to sort.
SubFieldNumber3 Optional Variant A secondary field number by which to sort.

Example

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

Visual Basic for Applications
  Sub NewParagraphSort()
    Dim newDoc As Document
    Set newDoc = Documents.Add
    newDoc.Content.InsertAfter "pear" & Chr(13) _
        & "zucchini" & Chr(13) & "apple" & Chr(13)
    newDoc.Content.Sort SortOrder:=wdSortOrderAscending
End Sub

See Also