How, using VBA in MS Word, do I determine if paragraphs in table cells are numbered or bulleted?

Viewed 95

I need to find bulleted or numbered paragraphs that are in tables. How do I do that using VBA in MS Word documents? I've tried looping through each paragraph:

For Each DocPara In ActiveDocument.Paragraphs
  Set rngPara = DocPara.Range
  If rngPara.Tables.Count > 0 Then
     Set lRange = rngPara.Tables.Item(1).Cell(1, 1).Range
    'How to test if cell contents has pargraph(s) that are bulleted or numbered?
  End if
Next DocPara
2 Answers

As you are only interested in bulleted or numbered paragraphs that are in tables it is rather inefficient to loop through all the paragraphs in the document. Instead loop through all the tables and loop through the paragraphs in each table.

Dim para As Paragraph
Dim tbl As Table

For Each tbl In ActiveDocument.Tables
    For Each para In tbl.Range.Paragraphs
        With para.Range
            If Len(.ListFormat.ListString) > 0 Then
                'para is part of a list
            End If
        End With
    Next para
Next tbl

If you must process all the document's paragraphs there is a better way of determining whether a paragraph is in a table.

For Each DocPara In ActiveDocument.Paragraphs
  With DocPara.Range
    If .Information(wdWithInTable) Then
      'para is in table
    End if
  End With
Next DocPara
For Each DocPara In ActiveDocument.Paragraphs
    Set rngPara = DocPara.Range
    If rngPara.Tables.Count > 0 Then
        If Not rngPara.ListFormat.List Is Nothing Then
            'is a list?
            Debug.Print rngPara.ListFormat.ListString
        End If
    End If
Next DocPara
Related