For Each Next Loops

W

Will

I would like to create a For Each Next loop but I am
having problems because I don't yet know how to declare
variables properly.

Basically, for each instance of style "Style1" in a
document, I would like to delete the paragraph above.

Thanks for any help
 
D

Doug Robbins

Try

Dim i As Long
With ActiveDocument
For i = .Paragraphs.Count - 1 To i Step -1
If .Paragraphs(i + 1).Style = "Style1" Then
.Paragraphs(i).Range.Delete
i = i - 1
End If
Next i
End With

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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