Using word, how do you sort a table of contents in alphabetical o

H

Herb Tyson [MVP]

Depends on the version. Assuming Word 2003 or recent earlier versions,
select the table, and choose Table - Sort from the menu.

If you're using Word 2007, select the table, click the Layout tab in the
ribbon, and in the Data group, click the Sort button.
 
S

Suzanne S. Barnhill

A table of contents in alphabetical order sounds a lot like an index. Note
that you can sort a TOC, but, unless you unlink it (or at least lock it), it
will resort itself in chronological order the next time you update it.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
H

Herb Tyson [MVP]

Actually, I somehow completely missed "of contents" when I too quickly dove
in. Since it's not really a table at all, in Word 2007, the Table Layout tab
won't be available.

In fact... It turns out that you CAN'T sort a Table of Contents unless you
unlink it (Ctrl+Shift+F9). Even if you lock the field, the sort command
gives an error ("Word cannot sort fields in the selection"), at least in
Word 2003.

Even if you unlink the TOC, School Secretary, you probably won't get the
results you want unless all of the TOC items are at the same level. That's
because Sort treats every paragraph the same, regardless of
level/indentaion. So, if you TOC is:


Food of Canada
Lobsters in the Maritimes
Lodging in Canada
Hotels in Alberta

The Sort command would produce:

Food of Canada
Hotels in Alberta
Lobsters in the Maritimes
Lodging in Canada
 
Joined
Nov 13, 2009
Messages
1
Reaction score
0
If anyone is still interested...

I had to do the same thing recently, and thought I'd share my macro. My use case was a songbook: the document itself is unsorted (so that I can add new pages as needed) but I wanted the table of contents to be sorted (so that people can find the songs). I created one index field at the front and then wrote the following macro:

Code:
Sub MarkTOC()

Dim par As Paragraph
Dim f As Field

ActiveDocument.ActiveWindow.View.ShowAll = True

For Each f In ActiveDocument.Fields
    If f.Type = wdFieldIndexEntry Then
        f.Delete
    End If
Next

For Each par In ActiveDocument.Paragraphs
    If par.Style = "Heading 2" Then
        par.Range.Select
        Selection.Collapse (wdCollapseStart)
        newField = ActiveDocument.Fields.Add(Selection.Range, _
           wdFieldIndexEntry, """" & Left(par.Range.Text, Len(par.Range.Text) - 1) & """", False)
    End If
Next

ActiveDocument.ActiveWindow.View.ShowAll = False
ActiveDocument.Fields(1).Update

For Each f In ActiveDocument.Fields
    If f.Code = " XE """" " Then
        f.Delete
    End If
Next

Selection.HomeKey wdStory

End Sub

The result was a nicely formatted "index" field which I decided to call a "table of contents".
Here's a picture:
20091113-268-116kb.jpg
 
Joined
Jun 10, 2012
Messages
1
Reaction score
0
:bow:
Thank you DavidHunt for that macro.

RE: The topic itself may be old, but the subject is still valid today :cheers:


Folks - READ please...

Took me a while to understand that this macro only 'marks' any text of type "Heading 2", as an "Index" field. THEN, we still need to create an "Index".

The macro automates selection and the marking of all titles we want to appear in the Index we want to create ...And I like it.


But, it doesn't create an alphabetized Table of Content!

Boy, did I scratch my head... and I hope these comments will help others avoid spending 4 hours, trying to get a result as per the topics' first question, out of this macro.... (which is "How to alphabetize a Table of Content") (ToC) :confused: :mad: :blush: :( :cry:

Folks - It is not a solution for that problem. And I was counting on your macro SOOOO much, David! :)



I (also) would LOVE to have an alphabetized ToC, because we can Ctrl-click on an entry, to go to the paragraph... Directly, from the ToC table.

I guess I must resign myself to understand that there is REALLY NO WAY to do that... in Office 2007...

Ahhhhhhh Dang, all hopes dashed.... Hopefully newer Word versions will do that...:drool:



If you know of anything new under the sun that would allow that, please reply. :blush:
 
Last edited:
Joined
Mar 18, 2013
Messages
2
Reaction score
0
Hello
I had to register to post this so I hope it's of some help:)

I've only done this in word 2007 with a TOC generated using 1 heading level
howto:
Generate your toc - select your toc
then press ctrl+shift+F9 while the toc is selected (this unlinks the TOC)
The TOC content is now unlinked from the field and should still be selected - simply sort the selection by paragraph
Of course every time you alter the document you will have to generate a new toc and repeat the above procedure but you will have an alphabetised toc with page numbers:D
Hope this helps
Eddie
 
Joined
Mar 18, 2013
Messages
2
Reaction score
0
you will have an alphabetised toc with page numbers:D
e
On further investigation it seems that Microsoft in their infinite wisdom also remove the hyperlinks so you can only manually go to the page - you have a static TOC.:(
Eddie
 
Joined
Aug 6, 2013
Messages
1
Reaction score
0
This worked for me, its from Yahoo answers (I'm unable to include the link in this post :()


Highlight the text that you want to alphabetize. Click on the Home tab. In the Paragraph area, there is a button marked AZ with a down arrow next to it. That is the sort button. Click on that and fill out the Sort Text fields as needed, click OK, and your text will be sorted into alphabetical order. If you're not happy with the results or want to change it back, use the undo function. Then update your TOC to incorporate the sorting changes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top