Loop Search

S

supersub15

Hi there,

I have a document where some of the text with the "Caption" style have
the "Keep with Next" option checked. I want to loop through all the
Caption styles and uncheck the option.

I created this macro, but it is not really looping. It gets stuck on
the first occurrence and doesn't move to the next Caption style.

With ActiveDocument.Content.Find
.ClearFormatting
.Style = "Caption"
Do While .Execute(FindText:="", Forward:=True, Format:=True) =
True
With Selection.ParagraphFormat
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
End With
Loop
End With

Any help is appreciated.
Carlos
 
H

Helmut Weber

Hi Supersub15,

don't really know what's wrong with your code,
maybe it is that you haven't reset all search and replace options.
However, if defining a new range, you don't have
to worry about options.

OK, this one works for me:

Sub Test52()
Dim rngDcm As Range
Set rngDcm = ActiveDocument.Range
With rngDcm.Find
.Style = "BodyText"
While .Execute
' rngDcm.Select
With rngDcm.ParagraphFormat
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
End With
Wend
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
H

Helmut Weber

hmm...

maybe redefining the style in question
would be a better idea.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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