by Allen Wyatt
(last updated September 14, 2019)
Justin is putting together a document that has many references that look like "ABC 12:34," and he wants to create index entries for all of them. He is able to use wildcards in Find and Replace to find these references, but he has not been able to find a way to create an index entry for each instance that is found.
One way to create the index you want is to rely on what Microsoft calls a "concordance file." This is nothing but a list of things you want indexed and an indication of how you want them indexed. Word then uses the concordance file as a guide in adding the index entries to your main document.
Let's look at the concordance file first. It is very simply constructed, containing nothing but a single two-column table. In the left column, each row should indicate a different term you want indexed in your main document. In Justin's case, he would need to list each unique "ABC 12:34" combination. In the right column each row would contain the index entry desired for the term to the left. In many cases this may mean that the right column simply repeats what is in the left, but it wouldn't necessarily if you want to specify different wording for the index entry or you want a subentry included. (If you want a subentry, you would use the main index entry followed by a colon and then the subentry.)
Once the concordance file is complete, save it away. Now you can open your main document and follow these steps:
Figure 1. The Index dialog box.
That's it; Word uses the contents of the concordance file as the guide for adding index entries to your main document. When it is done, you can insert your index wherever you want.
One thing I find helpful whenever I'm going to let Word perform some sort of mass operation on a document is to actually make sure I keep an extra copy of the document sitting around. Thus, before you apply the concordance file using the steps above, you might want to make a copy of your unaltered document. This is simply a safety precaution in case I, personally, messed something up in the concordance file.
If you don't want to go the route of creating a concordance file, you could use a macro to add the index entries. This is an example:
Sub CreateManyIndexEntries() Dim sFindPattern As String Dim sTemp As String ' Indicate the pattern to find sFindPattern = "^$^$^$ ^#^#:^#^#" ' Jump to beginning of document Selection.HomeKey Unit:=wdStory ' Find first instance of pattern Selection.Find.ClearFormatting With Selection.Find .Text = sFindPattern .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .IgnoreSpace = False End With Selection.Find.Execute While Selection.Find.Found ' Create what we want for index entry, ' ensuring that any colons are escaped out sTemp = Replace(Selection, ":", "\:") ' Create the actual index entry ActiveDocument.Indexes.MarkEntry _ Range:=Selection.Range, _ Entry:=sTemp, _ EntryAutoText:="", _ CrossReference:="", _ CrossReferenceAutoText:="", _ BookmarkName:="", _ Bold:=False, _ Italic:=False ' Set up next Find operation Selection.Collapse wdCollapseEnd Selection.Find.Execute Wend End Sub
The macro jumps to the beginning of the document and finds the first instance of whatever is in the sFindPattern variable. As shown above, the variable contains a pattern—three letters followed by a space, then two digits, a colon, and two digits. (This is the pattern that Justin specified.) If a match is found, then an index entry is created that matches whatever was found. The index entry is inserted in the document and then the next occurrence of the pattern is looked for. This is repeated for each instance of the pattern in the document.
The macro approach is more of a brute-force method of creating the index entries. That's because it isn't as flexible as using the concordance file; it doesn't handle creating index entries that are different from what you are searching for, nor does it handle subentries.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13674) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
If you have a word that includes punctuation as part of the word itself, then you may be frustrated by how Word treats ...Discover More
If you decide to create a master document, it is easy to do by just adding one or more subdocuments to an existing ...Discover More
One part of the grammar tools provided with Word is a thesaurus that helps you find all sorts of word variations. One ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.