View Single Post
 
Old 03-19-2019, 04:52 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following function will selectively delete headers and footers from the document. You could use it with http://www.gmayor.com/document_batch_processes.htm as a custom process to handle the folders containing the documents. Try it on a single example before running it on many documents to ensure that it deletes what is required in your documents.

Code:
Function DeleteHeaders(oDoc As Document) As Boolean
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim oSection As Section
    On Error GoTo err_Handler

    For Each oSection In oDoc.Sections
        For Each oHeader In oSection.Headers
            If oHeader.Exists Then
                Select Case oHeader.Index
                    Case wdHeaderFooterFirstPage
                        'do nothing or oHeader.Range.Delete as required
                    Case wdHeaderFooterPrimary
                        oHeader.Range.Delete
                    Case wdHeaderFooterEvenPages
                        oHeader.Range.Delete
                End Select
            End If
        Next oHeader
        For Each oFooter In oSection.Footers
            If oFooter.Exists Then
                Select Case oFooter.Index
                    Case wdHeaderFooterFirstPage
                        'do nothing or oFooter.Range.Delete as required
                    Case wdHeaderFooterPrimary
                        oFooter.Range.Delete
                    Case wdHeaderFooterEvenPages
                        oFooter.Range.Delete
                End Select
            End If
        Next oFooter
    Next oSection
    DeleteHeaders = True
lbl_Exit:
    Set oSection = Nothing
    Set oHeader = Nothing
    Set oFooter = Nothing
    Exit Function
err_Handler:
    DeleteHeaders = False
    Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote