0
votes

I have a document with various headings. I would like to be able to do the following:

  1. Find a Specific Heading from a "Heading 1" style.
  2. Delete the heading, the content following the heading to and including the next page break.

So delete: heading + its content + page break

I know how to find text using a Word macro but I do not know how to search only the headings.

Here is what needs to be deleted

Your help is greatly appreciated.

1
I know how to find text using a Word macro but I do not know how to search only the headings - same as searching for text, but with setting the .Style property of the Find object to the name of the style.GSerg
Your page break is manually placed? like series of dots with the word Page Break?L42

1 Answers

0
votes

I figured out that you need to enable extend between selections.

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 3") ' Search only "Heading 3"
    With Selection.Find
        .Text = "MIPwDMU"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Extend
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "^m"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
    End With
    Selection.Find.Execute
    Selection.Delete

This will delete all text between the Heading and the Page Break.