Hello,
I have previously had marvelous help from here creating some vba code for an ongoing project I'm doing. It runs several jobs on Word documents in whatever folder I select. Sometimes, I have a job to do that has nested folders, and I have to run the vba code on each individual folder. This is a bit annoying, but it's rare enough that it hasn't been bad enough to ask for help.
Now it is! I've had a job come in with 10 plus folders and each one of those folders has 1 or 2 or more sub folders, and each one of those has 4 subfolders! It's taking me forever to select all of those folders. Driving me batty.
Is there a way to automatically run the vba code on all subfolders as well as the main folder I select?
Here's the code I'm using now:
Code:
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc")
While strFile <> ""
Application.ScreenUpdating = False
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
With .Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Text = "Test Text 1"
.Replacement.Text = "Replacement Text 2"
.Execute Replace:=wdReplaceAll
.Text = "Test Text 2"
.Replacement.Text = "Replacement Text 2"
.Execute Replace:=wdReplaceAll
.Text = "Test Text 3"
.Replacement.Text = "Replacement Text 3"
.Execute Replace:=wdReplaceAll
End With
.Fields.Unlink
.RemoveDocumentInformation (wdRDIAll)
.Close SaveChanges:=True
End With
End If
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Thanks in advance for any help you can give!