View Single Post
 
Old 12-18-2013, 04:49 PM
fumei fumei is offline Windows 7 64bit Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Code:
Sub ReplaceTextInHeader()
Dim oHF As HeaderFooter
Dim oSection As Section
Dim myfle
PathToUse As String
PathToUse = "C:\Test\"
myfile = Dir(PathToUse & "*.doc")
Do While myfle <> ""
  Documents.Open (PathToUse & myfile)
     For Each oSection In ActiveDocument.Sections
        For Each oHF In oSection.Headers
           oHF.Range.Text = Replace(oHF.Range.Text, "Revision", "Final")
        Next
     Next
  ActiveDocument.Close SaveChanges:=wdSaveChanges
  myfile = Dir()
Loop
End Sub
If the replace is just text, and just in the header - "that will go through and replace text in a header" - then why bother going through the storyranges. Just deal with the headers.

The code above replace the word "Revision" with "Final" in ALL headers, in ALL documents in the folder.
Reply With Quote