Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2014, 03:32 PM
macropod's Avatar
macropod macropod is offline Find & Replace in Header/Footer in 1000 files Windows 7 32bit Find & Replace in Header/Footer in 1000 files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

This can be done quite easily via a macro. For example, the following macro allows you to browse to a folder containing the documents you want to process, then replace a given string in all documents in that folder automatically.
Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document, Sctn As Section, HdFt As HeaderFooter
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdDoc
    For Each Sctn In .Sections
      For Each HdFt In Sctn.Headers
        If HdFt.LinkToPrevious = False Then
          With HdFt.Range.Find
            .ClearFormatting
            .Text = "Old Header Text"
            .Replacement.Text = "New Header Text"
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .Execute Replace:=wdReplaceAll
          End With
        End If
      Next
      For Each HdFt In Sctn.Footers
        If HdFt.LinkToPrevious = False Then
          With HdFt.Range.Find
            .ClearFormatting
            .Text = "Old Footer Text"
            .Replacement.Text = "New Footer Text"
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .Execute Replace:=wdReplaceAll
          End With
        End If
      Next
    Next
    .Close SaveChanges:=True
  End With
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
For macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find &amp; Replace in Header/Footer in 1000 files Find & Replace in Header/Footer PReinie Word 6 01-22-2014 06:45 PM
Footer Find & Replace Operation? binar Word 1 02-05-2013 10:39 PM
Find &amp; Replace in Header/Footer in 1000 files Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Find &amp; Replace in Header/Footer in 1000 files header & footer avi_sai Word 1 12-03-2011 10:52 AM
Find &amp; Replace in Header/Footer in 1000 files Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:46 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