For Each Paragraph loop producing odd result

N

Nick Transier

I am working through a word document and parsing information out. I have
lots of type/format handling in the form of if-then-else loops. However,
when selecting the paragraph immediately after the table of contents, the
para.range.select function selects both that paragraph and then entire TOC.
Any idea why this happens? I have setup watch variables and the para object
is of type "Normal" and not "TOC", but for some reason on screen it is
selected with the TOC as well. I am baffled. I have tried putting hard
returns and such in to get around the problem, but I have had no luck.

My Loop Looks like this:
For each para in ActiveDocument.Paragraphs
'Do stuff
Next Para

My Document Looks like this
(TOC)
1. Section 1 ..... 1 (paragraph mark)
1.1 SubSection 1 ....... 1 (paragraph mark)
(paragraph mark) <----- This para object causing the problem
Section 1 (paragraph mark)
Text Under Section 1 (paragraph mark)
(paragraph mark)
Section 1.1 (paragraph mark)
Text Under Section 1.1 (paragraph mark)
(etc)
 
R

Ravi \(Newgen\)

Hi Nick,

I think that paragraph is last paragraph in TOC filed.
Same thing will happen when you select first paragraph of
TOC.

Suggestion: After generating TOC, select entire TOC
content and press Ctrl+Shift+F9 to unlink TOC field.

Hope this is useful.

-Ravi
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Nick Transier > écrivait :
In this message said:
I am working through a word document and parsing information out. I have
lots of type/format handling in the form of if-then-else loops. However,
when selecting the paragraph immediately after the table of contents, the
para.range.select function selects both that paragraph and then entire TOC.
Any idea why this happens? I have setup watch variables and the para object
is of type "Normal" and not "TOC", but for some reason on screen it is
selected with the TOC as well. I am baffled. I have tried putting hard
returns and such in to get around the problem, but I have had no luck.

My Loop Looks like this:
For each para in ActiveDocument.Paragraphs
'Do stuff
Next Para


You could test for the content of the para.range, if it contains the TOC
field, skip the "Do Stuff" and go to the next paragraph?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
Top