Finding out if a paragraph is in a table

R

Rod

I have some long documents (400+ pages) in which most of the text is in
tables. There are around 80,000 paragraphs including those in tables

I am only interested in the paragraphs that are not in tables. Does anyone
know of a way to efficiently either form such a collection or to test if a
paragraph is within a table.

Something like

For Each myPara In ParagraphsNotInTables
........
Next

or

If myPara IsInTable Then
'ignore
Else
.....


many thanks in advance
Rod
 
J

Jean-Guy Marcil

Rod was telling us:
Rod nous racontait que :
I have some long documents (400+ pages) in which most of the text is
in tables. There are around 80,000 paragraphs including those in
tables
I am only interested in the paragraphs that are not in tables. Does
anyone know of a way to efficiently either form such a collection or
to test if a paragraph is within a table.

Something like

For Each myPara In ParagraphsNotInTables
.......
Next

or

If myPara IsInTable Then
'ignore
Else
....


many thanks in advance
Rod

'_______________________________________
Dim myPara As Paragraph

For Each myPara In ActiveDocument.Paragraphs
If Not myPara.Range.Information(wdWithInTable) Then
'Process it
End If
Next
'_______________________________________

Depending on what you want to do, in order to make the code execute much
faster it might be worth considering copying the document to a temporary
document, delete all the tables, and then process the remaining paragraphs.
But it all depends on what you are actually doing with those paragraphs...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

Dim myPara As Paragraph
For Each myPara In ActiveDocument.Paragraphs
If Not myPara.Range.Information(wdWithInTable) Then
' do something with myPara
End If
Next

Although you could construct a collection of the paragraphs that aren't in
tables, it would take a loop like the one above to add the members to the
collection, and then you'd still have to do the processing of those members.
That's more work, not less.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

Shauna Kelly

Hi Rod

You need the .Information property, such as
If ActiveDocument.Paragraphs(1).Range.Information(wdWithInTable) then
msgbox "This paragraph is in a table"
endif
or the count of the number of tables
If ActiveDocument.Paragraphs(1).Range.tables.count > 0 then
msgbox "This paragraph is in a table"
endif

If you're dealing with many large tables one of other of those might perform
better; only empirical testing will tell.

See also
Maximising the performance of Word tables
http://www.word.mvps.org/FAQs/TblsFldsFms/FastTables.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
R

Russ

Rod,

To use process similar to what Jean Guy suggested...
"Depending on what you want to do, in order to make the code execute much
faster it might be worth considering copying the document to a temporary
document, delete all the tables, and then process the remaining paragraphs.
But it all depends on what you are actually doing with those paragraphs..."

....You could loop through all the tables and make the font hidden
temporarily while you process the unhidden paragraphs.
Sample code:

Public Sub HideTables()
Dim objTable As Word.Table
Dim blnShowAll As Boolean

blnShowAll = ActiveWindow.ActivePane.View.ShowAll
Application.ScreenUpdating = False
For Each objTable In ActiveDocument.Tables
objTable.Range.Font.hidden = True
Next objTable
ActiveWindow.ActivePane.View.ShowAll = False
Application.ScreenUpdating = True
Application.ScreenRefresh

'Something with the TextRetrievalMode _
may be needed to ignore hidden text.
'ActiveDocument.Content.TextRetrievalMode.IncludeHiddenText _
= False
MsgBox "Work on other paragraphs in this part of code."

Application.ScreenUpdating = False
ActiveWindow.ActivePane.View.ShowAll = blnShowAll
For Each objTable In ActiveDocument.Tables
objTable.Range.Font.hidden = False
Next objTable
Application.ScreenUpdating = True
Application.ScreenRefresh

End Sub
 

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