My loop never stops!

C

Cissy

Hi,

My macro starts by going to the top of the document, then it does a simple
procedure on certain paragraphs in the document. I want my procedure to loop
until it reaches the end of the document since there will be varying numbers
of paragraphs in each document. Is there a way to do this? I'm using Word
XP. Thank you!
 
K

Klaus Linke

Cissy said:
Hi,

My macro starts by going to the top of the document, then it does a
simple procedure on certain paragraphs in the document.
I want my procedure to loop until it reaches the end of the document
since there will be varying numbers of paragraphs in each document.
Is there a way to do this? I'm using Word XP. Thank you!


Dim myPara as Paragraph
For each myPara in ActiveDocument.Paragraphs
If (Some_condtion_on_the_paragraphs) Then
' do something with those paragraphs
End If
Next myPara

If you can find the "certain paragraphs" (that is, if they all share some
special kind of formatting or text), a Find/Replace would likely be faster.

Regards,
Klaus
 
C

Cissy

Here's my macro, thanks:

Do

Selection.Find.ClearFormatting

Selection.Find.Style = ActiveDocument.Styles("Heading 2")

With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine
Selection.Delete Unit:=wdCharacter, Count:=1

Selection.TypeParagraph
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Hidden = True

Selection.Font.Color = wdColorRed

Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Style = ActiveDocument.Styles("BodyText")
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

Loop Until
'Errorhandler: Exit Sub

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