ListFormat.ListLevelNumber
is what you are looking for. Here is the code that displays the list level and the text of each ListParagraph
in the document:
Sub listLevels() Dim currentList As Range Dim i, numLists As Integer numLists = ActiveDocument.ListParagraphs.Count For i = 1 To numLists Set currentList = ActiveDocument.ListParagraphs(i).Range MsgBox currentList.ListFormat.ListLevelNumber & " " & currentList.Text Next End Sub
Of course, you can use the ListLevelNumber = 1
condition to access only top-level lists, ListLevelNumber = 2
for the second level, etc.
Is there a way to access the list item in one object along with all its subitems?
Actually, I donβt think this is a great way to do this if you do not build it yourself using recursion or something else (create an object with an array of children, and each child will have its own array of children, etc. .). I do not have this encoding, but hopefully the code I posted will allow you to accomplish what you want to do, and it is much easier.
In addition, ListFormat
also has some other members that can be useful if you do a lot with lists, which can be found in the Object Explorer to find out more.
Drew Gaynor
source share