![]() |
|
#1
|
||||
|
||||
![]()
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] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
PReinie | Word | 6 | 01-22-2014 06:45 PM |
Footer Find & Replace Operation? | binar | Word | 1 | 02-05-2013 10:39 PM |
![]() |
paulkaye | Word | 4 | 12-06-2011 11:05 PM |
![]() |
avi_sai | Word | 1 | 12-03-2011 10:52 AM |
![]() |
shabbaranks | Excel | 4 | 03-19-2011 08:38 AM |