Sort Word Table columns using Word VBA
The following function uses Selection.Sort, you can try alternative methods if selection is not possible / permissible
Function SortTable()
ActiveDocument.Tables(1).Select()
Selection.Sort(ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType _
:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, FieldNumber2 _
:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False, LanguageID _
:=wdEnglishUS)
Selection.MoveRight(Unit:=wdCharacter, Count:=1)
End Function
The above uses as three column table. Please customize it for your use
See also:
How to use .Net Array.Sort Function in VBA
No comments:
Post a Comment