View Single Post
 
Old 03-01-2020, 10:28 AM
Leslie Leslie is offline Windows 8 Office 2010
Novice
 
Join Date: Oct 2019
Posts: 13
Leslie is on a distinguished road
Default Find and Replace whole folder content - Word files

Much pretty sure about getting solution from this forum!

Got a code, and the code needs execution so that the pointed folder, containing Word files, completely 'Find and Replace' the files' content in whole.

Much obliged if the below code gets optimized too (quick execution)!
Below is the F/R code:
Code:
Sub FindAndReplaceMultiItems()
  Dim strFindText As String
  Dim strReplaceText As String
  Dim nSplitItem As Long
   
  Application.ScreenUpdating = False

  strFindText = "northenn,westenn"
  strReplaceText = "northern,western"
  
  nSplitItem = UBound(Split(strFindText, ","))

  ' Find each item and replace it with new one respectively.
  For nSplitItem = 0 To nSplitItem
    With Selection
      .HomeKey Unit:=wdStory
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = Split(strFindText, ",")(nSplitItem)
        .Replacement.Text = Split(strReplaceText, ",")(nSplitItem)
        .Format = False
        .MatchWholeWord = False
      End With
    Selection.Find.Execute Replace:=wdReplaceAll
  End With
Next nSplitItem

  Application.ScreenUpdating = True

MsgBox "DONE EXECUTION"
End Sub
Thanks.

Last edited by Leslie; 03-01-2020 at 11:07 AM. Reason: added description
Reply With Quote