by Allen Wyatt
(last updated February 6, 2021)
Mike has a long document that uses Word's automatic list numbering throughout it. He needs a way to search, possibly using Find and Replace, for specific numbered items in these lists. For instance, he may need to search for the second item in the lists. Mike can convert the lists to manual numbering and do the search, but he would like to find the items without having to do the conversion.
One way that you could approach this issue is to consider how you put your document together. You could, for instance, use styles for your numbered paragraphs. Specifically you could use a different style for each numbered item, such as defining styles called Item1, Item2, Item3, and so on. Once applied to your paragraphs, you could easily search for paragraphs using the appropriate styles.
If you don't want to go the style route, you would need to use a macro to find the items. You can do this if you look at each paragraph in a document and determine if it has something in its .ListString property. If it contains what you are looking for, then you know you have found a desired list item. Here's an example of a macro that will do the trick:
Sub FindParagraphNumber() Dim sItemNum As String Dim p As Paragraph Dim sTemp As String Dim iChk As Integer Dim iCount As Integer Dim bStopped As Boolean sItemNum = InputBox("Find what item number?") If sItemNum > "" Then iCount = 0 bStopped = False ' Start going through each paragraph For Each p In ActiveDocument.Paragraphs sTemp = p.Range.ListFormat.ListString If sTemp Like "*" & sItemNum & "*" Then ' We found a match iCount = iCount + 1 ' Show the paragraph p.Range.Select ActiveWindow.ScrollIntoView Selection.Range, True ' Ask if searching should stop iChk = MsgBox("Keep looking?", vbYesNo) If iChk = vbNo Then bStopped = True Exit For End If End If Next p ' Put together the results message sTemp = sItemNum & " was not found in any paragraph numbers" If iCount > 0 Then sTemp = sItemNum & " was found " & iCount & " time(s)" End If If bStopped Then sTemp = sTemp & " before the search was stopped" End If sTemp = sTemp & "." MsgBox sTemp End If End Sub
Note that when you run the macro, you are asked for the item number you want. In Mike's case, he would enter "2", without the quote marks. Each paragraph is then inspected, and if there is a match between what Mike entered and what is in the .ListString property, then the item is selected and displayed on the screen. At that point, Mike can choose to continue looking or stop searching.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13344) 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!
Word allows you to search for specific ASCII codes in a document. If you use codes to search for alphabetic characters, ...Discover More
Want to change the order of the day and month in a date? This tip shows you how you can do so using the Find and Replace ...Discover More
When using Find and Replace, how your replacements are formatted will depend on how the text being replaced is formatted. ...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.
Visit the WordTips channel on YouTube