Sunday, July 20, 2008

Sort Columns of the Table using Word VBA

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()


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 _


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

Case in-sensitive comparison

No comments:

Post a Comment

Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.