Macro which searches through Folders and subfolders, but not the subfolders of subfolders!

RoundRocket

New Member
Joined
Nov 28, 2013
Messages
24
Hello,
I have a handy macro in excel 2007 which can perform a 'find and replace' on word documents depending on criteria placed on the excel worksheet. Currently, the macro is only searching through all docs in the initial folder it is navigated to search through and the first level of subfolders only, i'm wondering how i can get this to search through all subfolders of subfolders in the folder until it runs out of subfolders to search?? any help, suggestions you could give would be very much appreciated. Here is the snippet of code i currently have which relates to the subfolders search, i'm thinking i need to add in /amend some more code within here although i'm new to vba so unsure how to proceed on this... many thanks, Alex

' Call word replace again for each subfolder
Dim subFolder As folder, oFol As folder
Dim fso As New FileSystemObject
Dim strUCFolder As String

Set oFol = fso.GetFolder(searchPath)
For Each subFolder In oFol.SubFolders
strUCFolder = UCase(subFolder)

If InStr(strUCFolder, "REPLACEMENTS") = 0 And InStr(strUCFolder, "DOCUMENT MEDIA") Then
Call WordReplace(subFolder, subFolder)
End If
Next


Set oFol = Nothing
Set fso = Nothing
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Can anyone please help with adjusting the vba code on my post above so that it will also search through subfolders of subfolders and continue to do so until it runs out of subfolders? the code above is only going one subfolder deep in the folder the macro points to, then the macro stops.

Is it a case of adding in another 'For Each'? something like oFol.Subfolders.subfolders? i'm pretty new to vba so would be very grateful for any help with amending this.
Many Thanks
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top