Written by Allen Wyatt (last updated January 13, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
Michele needs a way to count the number of bulleted lists or the number of numbered lists in a document. She wonders how this could be accomplished in Word.
This is a bit harder than one might imagine, the bottom line being that we can find no way to generate a count reliably. The reason for this may take a bit of explaining.
There are multiple ways you can add styles to your document. For instance, you could click on either the Numbered List or Bulleted List tools on the Home tab of the ribbon to convert the current paragraph (or paragraphs) to a list. You could also start typing and allow Word to detect (via AutoFormat As You Type) whether you are creating a numbered list or a bulleted list. You could even define and apply styles that designate what you want used as a list.
Regardless of the way you create your lists, Word associates a style with the paragraphs in the list. If you create and apply your own style, then that particular style is (of course) used. If you use the toolbar buttons or rely on AutoFormat to create the lists, then Word automatically applies the List Paragraph style. (Yes, it uses the exact same style regardless of whether it is a numbered or bulleted list.)
Since styles are associated with the list, you can quickly determine how many instances of the style are in use. All you need to do is to display the Styles task pane (display the Home tab of the ribbon and click the small icon at the bottom-right of the Styles group). Locate the style used for your lists, hover the mouse pointer over that style name, and then click the down-arrow that appears to the right of the name. You'll see something similar to one of the following appear:
If what you see matches the first format, then select that option. When you hover over the style name and click the down-arrow again, what you see should match the second format.
You might think that this shows you the number of lists in your document. It doesn't; it only shows you the number of paragraphs formatted with this particular style. Thus, if you have a single list that is comprised of 6 items, then the style count returned will be 6. Thus, this approach—counting styles—doesn't provide a reliable way to determine a list count.
The other way you might consider is to use a macro to determine how many lists are in your document. Word maintains a Lists collection and makes it available to VBA. You can step through each list in the document and examine its ListType property. This property can actually be one of seven different values, as indicated by the following enumerations:
You can probably figure out what each of these lists types entails, but how they play out in reality can be a bit perplexing. As an example, consider the following macro:
Sub CheckLists() Dim oL As List Dim sMsg As String Dim J As Integer Dim K As Integer J = ActiveDocument.Lists.Count For Each oL In ActiveDocument.Lists K = K + 1 oL.Range.Select sMsg = "This is list " & K & " of " & J sMsg = sMsg & " lists in the document." & vbCrLf & vbCrLf sMsg = sMsg & "This list is this type: " Select Case oL.Range.ListFormat.ListType Case wdListBullet sMsg = sMsg & "wdListBullet" Case wdListListNumOnly sMsg = sMsg & "wdListListNumOnly" Case wdListMixedNumbering sMsg = sMsg & "wdListMixedNumbering" Case wdListNoNumbering sMsg = sMsg & "wdListNoNumbering" Case wdListOutlineNumbering sMsg = sMsg & "wdListOutlineNumbering" Case wdListPictureBullet sMsg = sMsg & "wdListPictureBullet" Case wdListSimpleNumbering sMsg = sMsg & "wdListSimpleNumbering" End Select MsgBox sMsg Next oL End Sub
If you have a document that contains lists and run this, it will select each list, in turn, and display a message box that shows what type of list Word thinks the selection represents. The problem is, if your text contains two lists interspersed by a paragraph or two of text, Word considers it a single list of the wdListMixedNumbering type. In other words, it doesn't accurately figure out what is a list and what isn't a list. This makes this particular approach unreliable for counting how many lists are in your document, although it is more accurate than using the count-the-styles approach.
The bottom line, as mentioned at the beginning, is that there is no way that we can determine to accurately count the number of bulleted and numbered lists in a document.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13528) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
When designing documents there are two types of lists commonly used: numbered lists and bulleted lists. This tip ...
Discover MoreThere are two types of common lists you can create in Word: bulleted lists and numbered lists. You can switch between the ...
Discover MoreIf you want to change the formatting applied to numbers or bullets in your lists, you'll appreciate the information in ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-05-22 08:11:43
Ken Endacott
A better approach is to identify a paragraph’s List number, type of List and other paragraphs in the same List. The method works irrespective of the way the List was created or the styles used. This approach does not cover numbering from SEQ fields, for example in captions.
The following macro identifies the selected paragraph’s List and gives the option to highlight all paragraphs in the List, ignoring interspersed paragraphs. With the addition of an unhighlight option and a modal form, the macro is a very useful tool to help resolve numbering problems.
Sub ShowList()
' **** Find what List this paragrah belongs to and highlight all paragraphs in that list ****
Dim aRange As Range
Dim aList As List
Dim aPara As Paragraph
Dim j As Long
Dim m As Long
Dim LstDescr
LstDescr = Array( _
"has no bullets, simple, outline numbering and no caption numbering", _
"has listnum fields in body of paragraph", _
"is bulleted", _
"has simple numbering", _
"is an outline numbered list", _
"has mixed lists applied", _
"is picture bulleted", _
"has unknown numbering")
Set aRange = Selection.Range.Paragraphs(1).Range
aRange.Select
' determine if the paragraph is in a list
j = 1
m = -1
Do While j <= ActiveDocument.Lists.Count
Set aList = ActiveDocument.Lists(j)
For Each aPara In aList.ListParagraphs
If aPara.Range.InRange(aRange) Then
m = j
Exit Do
End If
Next aPara
j = j + 1
Loop
If m = -1 Then
MsgBox "Paragraph is not in a list"
Exit Sub
End If
j = aRange.Paragraphs(1).Range.ListFormat.ListType
If j < 0 Or j > 6 Then j = 7
If MsgBox("This paragraph is part of List" & Str(m) & " that " & LstDescr(j) _
& vbCrLf & vbCrLf & "Highlight all paragraphs in this List?" _
, vbYesNo) = vbYes Then
For Each aPara In ActiveDocument.Lists(m).ListParagraphs
aPara.Range.HighlightColorIndex = wdRed
Next aPara
End If
End Sub
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