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

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

Case in-sensitive comparison

No comments:

Post a Comment

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...

Visual Basic for Applications (VBA) Forum (recent threads)

CodeKeep VBA Feed

Visual Studio Tools for Office Forum (recent threads)

Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.

Office Business Applications (OBA) Team Blog

MSDN Code Gallery Published Resources For Tag VSTO

microsoft.public.vsnet.vstools.office Google Group