Sub x_SearchAndReplace_MultipleFiles_Folders_Subfolders()
Dim FSO As Object
Dim ROOT As Object
Dim fldr As Object
Const strFolder = "C:\Trial\"
Set FSO = CreateObject("scripting.filesystemobject")
If Not FSO.folderexists(strFolder) Then
MsgBox "Folder '" & strFolder & "' not found - Exiting routine", , "Error"
Exit Sub
End If
Set ROOT = FSO.getfolder(strFolder & "\")
processFolder ROOT.path
For Each fldr In ROOT.subfolders
processFolder fldr.path & "\"
Next
End Sub
Sub processFolder(strFolder As String)
Dim strFile As String
Dim doc As Document
Dim rng As Word.Range
Dim fileSet As Object
strFile = Dir$(strFolder & "*.docx")
Do Until strFile = ""
Set doc = Documents.Open(strFolder & strFile)
For Each rng In doc.StoryRanges
With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "15.500"
.Replacement.Text = "19.500"
.Replacement.Font.Size = 9
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next rng
doc.Save
doc.Close
strFile = Dir$()
Loop
End Sub
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.