Word 2000, Word XP, and Word 2003: How do I find out if a paragraph is in a table cell or a list?

R

Rick Gutzmer

As part of a large data mining effort, I am iterating through many word
documents, paragraph by paragraph, and processing each paragraph. Much to
my surprise and pleasure, all the table cells turn out to be paragraphs, and
part of the ActiveDocument.Paragraphs collection. My challenge is - how do
I know if a particular paragraph is part of a list, or inside a table cell?

Below is the psuedo-code for what I want to do.

Public Sub walkParas()
Dim parTemp As Word.Paragraph

For Each parTemp In ActiveDocument.Paragraphs
If isTableCell(parTemp) then
' process contents of table cells here
ElseIf isListItem(parTemp) then
' process list items here
Else
' process normal, in-line paras here
End If
End If
Set parTemp = Nothing
End Sub

Public Function isTableCell(parTest as Word.Paragraph) as Boolean
' here is my problem - how can I test for this?
isTableCell = False
End Function

Public Function isListItem(parTest as Word.Paragraph) as Boolean
' here is my problem - how can I test for this?
isListItem = False
End Function
 
R

Rick Gutzmer

After recording a few macros, analyzing them, and reading through the
properties and methods of the Paragraph and Range objects in the VBA Object
browser, I found my own answers.
If there is any more efficient way, particularly for the lists, please reply
with it.

Public Function isTableCell(parTest As Word.Paragraph) As Boolean
isTableCell = parTest.Range.Information(wdWithInTable)
End Function

Public Function isListItem(parTest As Word.Paragraph) As Boolean
isListItem = Not (parTest.Range.ListFormat.ListTemplate Is Nothing)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top