Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2019, 05:48 PM
Edszx's Avatar
Edszx Edszx is offline Batch applying a macro to remove Header and Footer using Batch Auto Addin Windows 10 Batch applying a macro to remove Header and Footer using Batch Auto Addin Office 2013
Novice
Batch applying a macro to remove Header and Footer using Batch Auto Addin
 
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
  #2  
Old 05-27-2019, 07:59 PM
gmayor's Avatar
gmayor gmayor is offline Batch applying a macro to remove Header and Footer using Batch Auto Addin Windows 10 Batch applying a macro to remove Header and Footer using Batch Auto Addin Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,474
gmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to all
Default

Change
Code:
For Each oSection In ActiveDocument.Sections
to
Code:
For Each oSection In oDoc.Sections
__________________
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
  #3  
Old 05-27-2019, 11:16 PM
Edszx's Avatar
Edszx Edszx is offline Batch applying a macro to remove Header and Footer using Batch Auto Addin Windows 10 Batch applying a macro to remove Header and Footer using Batch Auto Addin Office 2013
Novice
Batch applying a macro to remove Header and Footer using Batch Auto Addin
 
Join Date: May 2019
Posts: 2
Edszx is on a distinguished road
Default

Thank you very much, that was it, it's working as intended
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch change header text which is in a table marafubu Word VBA 1 05-16-2018 04:52 AM
Batch replace Header and Footer and QuickStyle Artmax Word VBA 12 06-22-2017 01:53 AM
Remove Compatibility Mode on DOCX files (batch) w64bit Word 17 02-01-2015 06:02 AM
Batch applying a macro to remove Header and Footer using Batch Auto Addin Trying to create a macro to batch edit hyperlinks martinlest Excel Programming 5 01-09-2015 09:34 AM
How do I remove header and footer captn1 Word 2 09-04-2010 04:14 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 12:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft