Creating an Index in MS Word

One of the major tasks while completing a book such as Laughing at the Devil is creating the index. If you don’t like drudgery, or are unsure what words to include, you might want to hire a professional. But if those ideas don’t scare you and you can figure out what searchers may really want to look up, the following will be helpful for MS Word users. (Seth Maislin’s tips at will also be of assistance.)

The first tool is a macro for finding sequential page numbers. It is useful in the final task of manually marking page ranges.

In his work Maislin points out that creating index page ranges in Word can’t be done automatically, but it can be done if the individual {XE} fields are manually erased and then replaced with a bookmark range. He also mentions that the index Word creates can be manually edited, but he doesn’t recommend doing so because if the index is updated, all the manual labor will be lost.

If your book creation process mirrors my own in any way, your index entries will be started well before your work is completed. (That is because you will mistakenly believe you are finished when you aren’t. Sometimes it takes more rounds of editing than you ever imagined, simply because new information makes its way into your life.) In this case, both methods Maislin outlines are fraught with peril.

The only time to perform manual editing or bookmark ranging of your index is as the very last step of the book creation process. If the bookmark ranges are created earlier, there is a high probability they will not be updated correctly during further edits. There is also the possibility of erasing the beginning or ending of a range, with unknown, but probably undesirable, consequences.

For these reasons I recommend leaving the {XE} fields alone and manually massaging the index as the very last step. The index has to be edited anyway, to add ‘nX’ for any endnote references (where ‘X’ is the page number) and to place “(continued)” on the topics that get split across multiple columns. And if you want your index to conform to style guides such as the Chicago Manual of Style, you must move some “See also” entries to the end of the topic, which Word doesn’t do. (The proper order to perform these tasks is to add the ‘nX’s’, then use the macros in this tips page, then relocate the ‘See also‘ entries, and finally place the ‘continued‘s. This makes it unnecessary to continually move the ‘continued‘s around when the columns wrap in different places because of the other changes.)

To facilitate this manual editing, the following macro searches for sequential numbers starting from the current cursor location. When it finds a sequential pair it highlights the second number and exits from the macro. At that point you can quickly change what needs to be changed. In some cases this may be nothing, as the macro doesn’t search for text between the entries, so a scenario like “topic1…12 / topic2…13” will highlight the ’13’.

In other cases, simply select the commas and digits that are unnecessary and type ‘Ctrl’ + ‘-‘ on the keypad (assuming a Windows US keyboard layout). This inserts the correct en-dash, so an entry like “topic1…28, 32, 33, 34, 40” becomes “topic1…28, 32–34, 40.”

To speed this step up even more, instead of always typing ‘Ctrl’ + ‘-‘ simply place an en-dash into the clipboard by highlighting the first one and typing ‘Ctrl’ + ‘C’, and then hitting ‘Ctrl’ + ‘V’ when the appropriate characters are highlighted.

An additional speed-up: assign the sequential-number macro to a keyboard shortcut. I used ‘Ctrl’ + ‘Shift’ + ‘Z’. Once you are used to those two combinations, the editing goes much quicker.

Before running this macro for the first time it is necessary to open Word’s ‘Find’ box, enter “[0-9]{1,3}” as the find text, check the ‘Use wildcards’ option, and perform a single search to get these options into Word’s memory. Don’t ask me why that had to be done (nor how much frustration ensued while determining this fact!). After doing that, simply place the cursor at the top of the index (or wherever you want to start searching from) and run the macro.

If you don’t assign the macro to a keyboard shortcut, another way to speed up the process a bit is to keep the macro editor open as a small window on your screen and hit its ‘Run’ button to proceed to the next instance after making an index change. It also helps to have Word non-maximized so both windows are visible at once, although you can use AuthHotKey or another utility to force a window to stay on top. But the keyboard shortcut leaves this method in the dust.

I have seen cases in which this process wouldn’t find sequential numbers, due to some bug deep within the bowels of MS Word, but closing and reopening the macro editor fixed that problem.

Here is the code:

Sub FindSequentialNumbers()
' FindSequentialNumbers Macro
' Macro recorded 8/4/2008 by David O'Neil
' After creating a macro called 'FindSequentialNumbers,' copy the following lines into it:
    Dim TextToFind As String ' number pattern to search for
    Dim FirstPatternStringFound As Range ' first number pattern string found
    Dim FirstNum As Double ' first number found
    Dim SecondNum As Double ' second number found
    Dim startRge As Range 'To save initial selection
    TextToFind = "[0-9]{1,3}"
    Set startRge = Selection.Range
    Application.ScreenUpdating = False
    With Selection.Range.Find
        .Text = TextToFind
        .Forward = True
        .MatchWildcards = True
        End With
    Do While Selection.Find.Execute
        If FirstPatternStringFound Is Nothing Then
            Set FirstPatternStringFound = Selection.Range
            FirstNum = FirstPatternStringFound
            SecondNum = Selection.Text
            If SecondNum = FirstNum + 1 Then
                StatusBar = "Pattern Matched"
                Exit Sub
                End If
            Set FirstPatternStringFound = Selection.Range
            End If
    Application.ScreenUpdating = True

' End copy
End Sub

The other tool is for those who use ‘…’ to separate the index entry from the page numbers. You will find Word sometimes uses single dots in those locations. To me, that looks terrible, and if you agree, and want to get rid of those isolated dots, the only way I found to accomplish that was to make a PDF of the index using Adobe Acrobat (or whatever PDF creation tool you have available) and then copy/paste that PDF text into a new Word document. In the copy, do a search for “[!.].[!.]”, again selecting the ‘Use wildcard’ option.

This will find all instances of isolated dots in that document. It is necessary to then add a space or two before the ‘tab’ that is at that location in the original document. (That is assuming it is an unwanted dot, and not a period that follows an abbreviation, such as ‘Dr.’.) After all the instances have been massaged in this manner, it is a good idea to repeat the process to make certain that the ‘spaces’ of the spaces have really gotten rid of the extraneous dots.

I’ve read that the newest version of Word opens PDFs, making the ‘copy/paste’ step unnecessary – just open the created PDF with Word.

As you can tell, Word is not a wonderful tool for creating indexes, but it is good enough to get the job done. I hope that you find these tips useful in that endeavor.

Leave a Reply

Your email address will not be published. Required fields are marked *

Search Site / View Categories / View Tags

All content © 2005-present by David O'Neil