How can i remove only footers from selected pages by VBA code.
How can i remove only footers from selected pages by VBA code.
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 enoughIf yuou want a particular footer to be removed then you need to provide more information.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
Graham Mayor - MS MVP (Word) 2002-2019
Visit my web site for more programming tips and ready made processes
http://www.gmayor.com
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
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