Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 06-18-2017, 11:50 PM
gmayor's Avatar
gmayor gmayor is offline Batch replace Header and Footer and QuickStyle Windows 10 Batch replace Header and Footer and QuickStyle Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

OK. In that case the following function will do that. The function is written to work as a user defined process with http://www.gmayor.com/document_batch_processes.htm which will handle the folders/documents, or you can call it from your own document selection process.

Basically it replaces any (or no) header and footer with the autotext entries from the normal template called @header and @footer, that you said you have created.

If you use the batch processor, ensure that you test it first on a single document to ensure that the autotexts do indeed produce the required results, before processing all the documents in a folder.

Code:
Function MyHeader(oDoc As Document)
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim strTemplate As String
Dim orng As Range
    strTemplate = Application.Options.DefaultFilePath(wdUserTemplatesPath)
    strTemplate = strTemplate & "\Normal.dotm"

    On Error GoTo err_Handler
    For Each oSection In oDoc.Sections
        For Each oHeader In oSection.Headers
            If oHeader.Exists Then
                Set orng = oHeader.Range
                orng.Text = ""
                Application.Templates _
                        (strTemplate).AutoTextEntries("@header").Insert Where:=orng, _
                                                                        RichText:=True
            End If
        Next oHeader
        For Each oFooter In oSection.Footers
            If oFooter.Exists Then
                Set orng = oFooter.Range
                orng.Text = ""
                Application.Templates _
                        (strTemplate).AutoTextEntries("@footer").Insert Where:=orng, _
                                                                        RichText:=True
            End If
        Next oFooter
    Next oSection
    MyHeader = True
lbl_Exit:
    Exit Function
err_Handler:
    MyHeader = 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
 

Tags
macro find and replace, styles, word 2016

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch replace Header and Footer and QuickStyle Find & Replace in Header/Footer in 1000 files amodiammmuneerk@glenmarkp Word 12 03-05-2018 03:31 AM
Batch replace Header and Footer and QuickStyle New to VBA - Find/Replace in MS Word 2010 that Searches Header/Footer mbreggs Word VBA 4 06-01-2016 08:02 AM
Batch replace Header and Footer and QuickStyle Find/replace font colour in all header/footer trillium Word VBA 4 10-20-2015 10:39 PM
Batch replace Header and Footer and QuickStyle Created VBA to Find and Replace in Body, Header and Footer with Highlighting the replacement text QA_Compliance_Advisor Word VBA 11 09-23-2014 04:40 AM
Batch replace Header and Footer and QuickStyle Find & Replace in Header/Footer PReinie Word 6 01-22-2014 06:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:00 AM.


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