Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2013, 04:49 PM
fumei fumei is offline Replace words within headers in multiple document Windows 7 64bit Replace words within headers in multiple document 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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace words within headers in multiple document Find and highlight multiple words in MS Word document AtaLoss Word VBA 37 09-22-2021 12:04 PM
Replace words within headers in multiple document Highlight and then replace multiple words redhin Word VBA 5 03-05-2013 05:42 AM
Replace words within headers in multiple document Macro to replace few words in the document ubns Word VBA 7 08-16-2012 10:33 PM
Multiple Headers in Same Worksheet Tom Excel 3 05-18-2011 03:22 PM
Multiple Headers boutells Word 1 06-05-2009 12:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:29 PM.


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