How to find out the number, or list level, or outline level, that is applied to a list-numbered paragraph, using VBA

Article contributed by Dave Rado

Figure 1

List number

You can get the number that has been applied to any list-numbered paragraph using the ListString property – for example:

MsgBox Selection.Paragraphs(1).Range.ListFormat.ListString

So if you run this code on the paragraphs in Figure 1, it will return nothing, 1, 1.1, and nothing, respectively.

List level

List level means the level in a numbering outline: so in Figure 1, the first and last paragraphs would have no list level, and the middle two would usually have list levels of 1 and 2 respectively.

You can get the list level that has been applied to any list-numbered paragraph using the ListLevelNumber property; for example:

MsgBox Selection.Paragraphs(1).Range.ListFormat.ListLevelNumber

Unfortunately, a paragraph that has no list numbering applied returns 1 – whereas it really ought to return nothing or 0, or 10, or 9999, or something that indicates that it has no List Level – but certainly not 1. This is a bug. So to distinguish unnumbered paragraphs from paragraphs which genuinely have a List Level of 1, you have to use something like:

If Selection.Paragraphs(1).Range.ListParagraphs.Count = 1Then
    MsgBox Selection.Paragraphs(1).Range.ListFormat.ListLevelNumber
   MsgBox "Not a numbered paragraph"
End If

Outline Level

Confusingly, perhaps, the Outline Level of a paragraph (in Word terminology) has nothing whatsoever to do with numbering, except in a tangential sense. The Outline Level really means the Heading level, or in other words, the level at which the paragraph appears in Outline View. It is the property that you see in the Format + Paragraph dialog, under Outline Level.

All built-in heading styles have an outline level, (Level 1 for a main heading, Level 2 for a subheading, and so on), whether they are numbered or not; and if you create your own Heading styles, they too will have an outline level, whether they are numbered or not. That is the difference between heading styles and all other styles; a Heading style is simply any style that has an Outline Level between 1 and 9. Conversely, outline numbered body text does not have an Outline Level (or to be more exact, its Outline Level is Body Text). So don't confuse the List Level and the Outline Level properties – they are very different beasts. In the case of numbered Headings, the Outline Level and List Level of the paragraph will be identical. But only in the case of numbered Headings.

You can get the outline level of any paragraph using the OutlineLevel property; for example:

MsgBox Selection.Paragraphs(1).OutlineLevel

If the OutlineLevel is Body Text, this code returns 10. So in Figure 1, the first and last paragraphs would return 1 and 2 respectively, and the middle two paragraphs would return 10.