Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 05-05-2009, 11:39 PM
Bird_FAT's Avatar
Bird_FAT Bird_FAT is offline Sort By Last Name in a List Sort By Last Name in a List Office 2007
Expert
 
Join Date: Apr 2009
Location: South East
Posts: 271
Bird_FAT is on a distinguished road
Arrow VB Version

Here's a bit of code that will automate the process for you. It will select all, convert to list, sort by column 2 and then reconvert to text:

Open your VB window (Alt+F11)
In the left hand window, look for 'Normal' and click on the +
Click the + next to Microsoft Word Objects
Double-click ThisDocument
Paste the code below
Import/Open your name list (make sure you only have names in your document)

Run the Macro:
(2003)
Tools > Macro > Macros > (choose 'Sort_Name_List) > Run

(2007)
View > Macro > View Macros > (choose 'Sort_Name_List) > Run


Code:
Sub Sort_Name_List()
'
' 06/05/2009 by Bird
'
    ScreenUpdating = False
    Selection.WholeStory
    Selection.ConvertToTable Separator:=wdSeparateByDefaultListSeparator, _
        NumColumns:=2, NumRows:=7, AutoFitBehavior:=wdAutoFitFixed
    With Selection.Tables(1)
        .Style = "Table Grid"
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = True
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = True
    End With
    Selection.Sort ExcludeHeader:=False, FieldNumber:="Column 2", _
        SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
        FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
        wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
        wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
        wdSortSeparateByCommas, SortColumn:=False, CaseSensitive:=False, _
        LanguageID:=wdEnglishUK, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
        "Paragraphs", SubFieldNumber3:="Paragraphs"
    Selection.Rows.ConvertToText Separator:=wdSeparateByDefaultListSeparator, _
        NestedTables:=True
    ScreenUpdating = True
End Sub
By putting this code in the 'ThisDocument' code, then it means that it will be available in all documents.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort By Last Name in a List how do i take my contact list to a new computer? blade Outlook 2 01-13-2011 07:03 AM
Sort By Last Name in a List List option shashijb Excel 1 12-18-2008 03:07 AM
Which app to use for list on Outlook? sus Misc 0 08-26-2008 08:46 AM
creating a categories list owwiii Outlook 0 08-09-2007 01:56 PM
Creating a Map From a List of Addresses aleccamp Excel 0 11-19-2005 03:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft