#1
|
|||
|
|||
Find & Replace in Header/Footer in 1000 files
Hi,
I have 1000 odd word files in which I want to replace Header & Footer text, is there an automate way to achieve this. is there any Microsoft or any third party tool available to address this ask, Thanks & Regards Amodiamm |
#2
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi Paul,
Appreciate for the macro code While using this macro it changes only one and the recent document header in the folder browsed.. kindly note that we have office 2003 documents. Any help is appreciated... Regards. MD Sari |
#4
|
|||
|
|||
It changes only one what? One header? One file? What do you mean by "recent document header"?
|
#5
|
|||
|
|||
It changes header in only one file among the multiple .doc files available in the folder
|
#6
|
|||
|
|||
Add-In
Have you looked at or tried: http://gregmaxey.com/word_tip_pages/...d_replace.html
|
#7
|
||||
|
||||
That strongly suggests the headers in the other files don't contain exactly the same content as whatever you've input as the 'Old Header Text'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Definitely. MD Sari, the code works as stated. If you are not getting the results you want then there is something different with your files.
|
#9
|
|||
|
|||
hi i'm new here. I was also trying to find the same and stumble here, and I am aware that this is an old thread but. I am using MS Word 2010 and as have mentioned it only works on the first word file. Currently because it does find and replace footer and header my only solution is to folder each file and run the macro to each folder as this is still fast than opening each file. @macropod is there anyway you can modify the code? thanks in advance.
|
#10
|
||||
|
||||
The code is post #2 will work on as many documents as your folder contains.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Thanks Paul, the reason it is not working is because my footer was done as Table? Would this macro run successfully on tabled-style header & footer?
|
#12
|
||||
|
||||
It makes no difference to the code whether the header/footer content is in a table - unless someone has gone and put that table in a textbox or a frame.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
I do not know how the footer is but i know it is a table. Though your code still usable for me and thank you.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Bad view when using Find and Find & Replace - Word places found string on top line | paulkaye | Word | 4 | 12-06-2011 11:05 PM |
header & footer | avi_sai | Word | 1 | 12-03-2011 10:52 AM |
Help with find and replace or query and replace | shabbaranks | Excel | 4 | 03-19-2011 08:38 AM |