Find a heading and remove the section break following it

V

Vidya

I need help with a find macro which searches for all 'Heading 1" in a
document and then searches for the first section break following it and
deletes the section break. There are other section breaks as well in the
document, I want to retain them. Kindly help.
 
T

Tony Jollans

Try this:

With ActiveDocument.Range: Do
With .Find
.ClearFormatting
.Style = ActiveDocument.Styles(wdStyleHeading1)
If Not .Execute("") Then Exit Do
End With
.Collapse wdCollapseEnd
With .Find
.ClearFormatting
If Not .Execute("^b", ReplaceWith:="", Replace:=wdReplaceOne)
Then Exit Do
End With
Loop: End With
 
V

Vidya

Hi,

Its working perfectly. I was struggling with two searches, unable to loop
them properly.

Thanks a lot for the help.

Regards,
Vidya
 

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