Written by Allen Wyatt (last updated July 6, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
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 Microsoft 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!
Got a list of words you don't want to appear in your documents? There are a number of ways that you can make sure they ...
Discover MoreOne of the viewing modes you can use for a document involves the use of the Navigation pane. This shows a quick outline ...
Discover MoreIf you need to move master documents or subdocuments from one place to another on your computer, you have to keep in mind ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2020-08-24 11:55:46
Gregg
That's wonderful, but how do I mass-delete index fields made in error? I don't want to have a backup Word document for every possible step that I might mess up. Maybe there is a find-and-replace variant that operates on whether the found text is a field and changes that to not be a field?
And what happens to index fields that I've made manually -- are they deleted when a concordance file is applied?
2019-09-14 05:05:55
Mike Dresel
This is a great tip. I will definitely be able to use it.
One general comment about "how to do X" instructions. Not everyone reads the entire list before starting, so anything that goes "Step 1; Step 2; Step 3; But first, do this" can be difficult/disasterous. I would recommend that the (very useful) suggestion to back up the document should come before the indexing instructions
Mike - who had written way too many instructions.
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments