For Each...Next is not advancing to next paragraph

T

toth.usenet

hi,

i'm trying to write a program which will select several paragraphs,
based on a key word, and then turn them into a table. most of it seems
to work but i can't get the For Each...Next to advance to the next
paragraph and i'm not sure why.

wherever the text "Step name :" is found in my document i would like
to select the current (n=1)+ the following 6 (n=7) paragraphs and turn
them into a table. then i would like to continue with the next
paragraph (n=8) and repeat the same procedure (search, select,
convert).

here is my code:

Dim SearchPara As Paragraph
Dim SelPara As Paragraph
Dim SelRange As Range

For Each SearchPara In ActiveDocument.Paragraphs
Set SelRange = SearchPara.Range
With SelRange.Find
.Text = "Step name :"
.Forward = False
If .Execute = True Then
If SelRange.Start = SearchPara.Range.Start Then
SelRange.MoveEnd Unit:=wdParagraph, Count:=7
SelRange.Select
Selection.ConvertToTable .......[snip]

End If
End If
End With
Next

so far this is working well and i can find the text, i can select the
next paragraphs and i can turn them into a table. however, i can not
get the program to advance to the next paragraph after the table, the
For Each...Next loop keeps going on the same selected paragraphs. i
assume it is related to the selection covering several paragraphs.

does anyone have an idea why this is happening, and how i could
resolve it?

any help is appreciated.

cheers,
thomas
 

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