Consulting

Results 1 to 4 of 4

Thread: How to remove all footers from a word file.

  1. #1

    How to remove all footers from a word file.

    How can i remove only footers from selected pages by VBA code.

  2. #2
    Footer is not a page attribute. There are potentially three footers for each section in the document. Your message title suggests that you want to remove all footers from a document, which is easy enough
    Sub removeallfooters()
    Dim oSection As Section
    Dim oFooter As HeaderFooter
        For Each oSection In ActiveDocument.Sections
            For Each oFooter In oSection.Footers
                If oFooter.Exists Then
                    oFooter.Range.Text = ""
                End If
            Next oFooter
        Next oSection
    lbl_Exit:
        Set oSection = Nothing
        Set oFooter = Nothing
        Exit Sub
    End Sub
    If yuou want a particular footer to be removed then you need to provide more information.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    I have many types of footers in the document, but specifically there is a footer which is in the following format "ABC 000001, ABC 000002, ABC 000003". so i want these footers to be removed which starts from ABC

  4. #4
    Whether the number is plain text or a page field, the following should work.

    Sub removeallfooters()
    Dim oSection As Section
    Dim oFooter As HeaderFooter
    Dim oRng As Range
    Dim bFields As Boolean
        bFields = ActiveWindow.View.ShowFieldCodes
        ActiveWindow.View.ShowFieldCodes = False
        For Each oSection In ActiveDocument.Sections
            For Each oFooter In oSection.Footers
                If oFooter.Exists Then
                    Set oRng = oFooter.Range
                    With oRng.Find
                        Do While .Execute(FindText:="ABC [0-9]{1,}", _
                                          MatchWildcards:=True)
                            oFooter.Range.Text = ""
                        Loop
                    End With
                End If
                ActiveWindow.View.ShowFieldCodes = True
                Set oRng = oFooter.Range
                With oRng.Find
                    Do While .Execute(FindText:="ABC ^d PAGE")
                        oFooter.Range.Text = ""
                    Loop
                End With
            Next oFooter
        Next oSection
        ActiveWindow.View.ShowFieldCodes = bFields
    lbl_Exit:
        Set oSection = Nothing
        Set oFooter = Nothing
        Set oRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •