0
votes

I've been looking around everywhere to find the code to delete the first 2 pages of each section of the document. The best I came up with is to go to an Absolute Bookmark("\Page") but that will not work for each section in the document - it should be relative to each section, since the sections can vary from 1 to unlimited.

Every section has the same 5 pages layout (although the content does vary). There are no headers which could be eventually looked-up. Also, I need to delete the headers and footers. So the code I have is the following:

Sub Macro1()
    Dim oSec As Section
    Dim oHead As HeaderFooter
    Dim oFoot As HeaderFooter

    For Each oSec In ActiveDocument.Sections
        For Each oHead In oSec.Headers
            If oHead.Exists Then oHead.Range.Delete
        Next oHead

        For Each oFoot In oSec.Footers
            If oFoot.Exists Then oFoot.Range.Delete
        Next oFoot
    Next oSec End Sub

This deletes the headers and footers in each section. In addition, I'd like to delete the first 2 pages out of the 5 within each section.

Could anyone help me out here?

1

1 Answers

2
votes

Try this:

Public Sub DeletePagesFromSections()

Dim oSec As Section
Dim i As Integer

Application.ScreenUpdating = False

For Each oSec In ActiveDocument.Sections
    For i = 1 To 2
        oSec.Range.Select
        Selection.Collapse
        ActiveDocument.Bookmarks("\page").Range.Delete 'this deletes current page
    Next i
Next oSec

Application.ScreenUpdating = False

End Sub