• RyanDev.com

  • How to Find and Replace Within Multiple Microsoft Office Word Documents

16th February 2008

How to Find and Replace Within Multiple Microsoft Office Word Documents

Download the full code.


Attribute VB_Name = “FindReplace”
Public Sub GlobalFindandReplace()
Dim oDoc As Word.Document
Dim oFile As File
Dim oFolder As Folder
Dim fs As FileSystemObject

Set fs = New FileSystemObject
Set oFolder = fs.GetFolder(”c:\ptr”) ‘the folder with all of the files

Application.DisplayAlerts = wdAlertsNone ‘don’t put up any prompts
For Each oFile In oFolder.Files ‘loop through all files in the folder
  If oFile.Type = “Microsoft Word Document” Then ‘only touch Word files
  Set oDoc = Application.Documents.Open(oFile.Path) ‘open the file
  ‘***********************
  ‘beginning of first find
  Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting
  With Selection.Find
  .text = “administrator”
  .Replacement.text = “Administrator”
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = True
  .MatchWholeWord = False
  .MatchByte = False
  .MatchAllWordForms = False
  .MatchSoundsLike = False
  .MatchWildcards = False
  .MatchFuzzy = False
  .Execute Replace:=wdReplaceAll
  End With
  ‘end of first find
  ‘************************
  ‘if a second find is needed copy the above code here

‘end of second find

End If
  ’save and close the document
  oDoc.Save
  oDoc.Close
Next oFile ‘move on to the next file
Application.DisplayAlerts = wdAlertsAll ‘turn alerts back on
End Sub


Download the full code.

posted in Microsoft Office, Microsoft Word | 0 Comments

  • Links

  • Calendar

  • September 2010
    S M T W T F S
    « Jun    
     1234
    567891011
    12131415161718
    19202122232425
    2627282930