MG said:
I had a post and string in here, and it seems to have
dissapeared, so forgive me for posting a new one.
Graham, you had just given me a public sub to be able to
find and replace all in the headers and footers ... I ran
it, and it did just what you said in the first document,
and proceded to flash up all the rest of the documents in
the folder. The only problem is that only the first
document was changed afterwards ... did the rest not save
with the change?
Thanks for all the help.
I didn't write the code (reproduced below) I only posted it. On the face of
it it looks OK, but the various elements of find and replace across a batch
of documents has been one of those jobs that has been put on a back burner,
so there are various bits of code on the MVPS web site associated with batch
processing. What it needs is an enthusiastic soul with the time available to
bring them together. To this end I have cross-posted this message to the vba
group for comment:
Public Sub BatchReplaceAllInHeaderFooter()
Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
PathToUse = "D:\My Documents\Temp\"
On Error Resume Next
Documents.Close Savechanges:=wdPromptToSaveChanges
FirstLoop = True
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
If FirstLoop Then
Dialogs(wdDialogEditReplace).Show
FirstLoop = False
Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub
Else
With Dialogs(wdDialogEditReplace)
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
If oHeader.Exists Then
.ReplaceAll = 1
.Execute
End If
Next oHeader
For Each oFooter In oSection.Footers
If oFooter.Exists Then
.ReplaceAll = 1
.Execute
End If
Next oFooter
Next oSection
End With
End If
myDoc.Close Savechanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
Web site
www.gmayor.com
Word MVP web site
www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>