Thread: [Solved] Pull all lists from document
View Single Post
 
Old 01-31-2024, 04:47 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Lets take a step back and think about this a little.

First, if you also want to grab headings which are numbered then they are ALSO going to be list items so you don't need a specific column for that information.

Second, if you run a find for nothing, what exactly do you think it will find?

So we need to consider alternate ways to achieve your aims and I'll start by asking what is the point of this activity? What is a collection of the list items in Excel going to do for you?

From a coding point of view, I thought a better way to iterate through the list items would be the following approach. Unfortunately, this does indeed return each list item but it iterates through the paragraphs in the order the lists were applied rather than the order that the paragraphs appear in the document. Perhaps if we included a paragraph index as an extra column you could simply sort on that to put the paragraphs in order.
Code:
  Dim aLP As Paragraph, aDoc As Document
  Set aDoc = ActiveDocument
  Debug.Print aDoc.ListParagraphs.Count
  For Each aLP In aDoc.ListParagraphs
    aLP.Range.Select
    With aLP.Range.ListFormat
      Debug.Print .ListType, .ListString, aLP.Range.Text
    End With
  Next aLP
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote