View Single Post
 
Old 05-27-2019, 05:48 PM
Edszx's Avatar
Edszx Edszx is offline Windows 10 Office 2013
Novice
 
Join Date: May 2019
Posts: 2
Edszx is on a distinguished road
Default Batch applying a macro to remove Header and Footer using Batch Auto Addin

Greetings, i've been reading this thread https://www.msofficeforums.com/word-...directory.html and i've been trying to adapt this macro:

Code:
Sub DeleteHeadFoot()
    Dim oHF As HeaderFooter
    Dim oSection As Section
    For Each oSection In ActiveDocument.Sections
        For Each oHF In oSection.Headers
            oHF.Range.Delete
        Next
        For Each oHF In oSection.Footers
            oHF.Range.Delete
        Next
    Next
End Sub
to work with Batch Auto Addin, because i need to apply it to hundreds of word documents (doc, docx, dot) with a subfolder structure, i'm using the example function included in that thread as an example

Code:
Function FontChangeArial16Blue(ByRef oDoc As Word.Document) As Boolean
  On Error GoTo Err_Handler
  With oDoc.Range.Font
      .Size = 16
      .Name = "Arial Unicode MS"
      .Color = wdColorBlue
   End With
  FontChangeArial16Blue = True
lbl_Exit:
  Exit Function
Err_Handler:
  FontChangeArial16Blue = False
  Resume lbl_Exit
End Function
And it currently looks like this:

Code:
Function DeleteHeadFoot(ByRef oDoc As Word.Document) As Boolean
    Dim oHF As HeaderFooter
    Dim oSection As Section
  On Error GoTo Err_Handler
        For Each oSection In ActiveDocument.Sections
        For Each oHF In oSection.Headers
        oHF.Range.Delete
        Next
        For Each oHF In oSection.Footers
        oHF.Range.Delete
        Next
        Next
  DeleteHeadFoot = True
lbl_Exit:
  Exit Function
Err_Handler:
  DeleteHeadFoot = False
  Resume lbl_Exit
End Function
It runs without errors with Batch Auto Addin, but no changes are made to the documents, im not a VBA programmer, so i would really appreciate any help to adapt this, thank you very much in advance.
Reply With Quote