Recursive search to go through all subfolders and rename files

vcsush

Board Regular
Joined
Oct 1, 2006
Messages
52
Hi All

First up...thanks for any help.

I have adapted a piece of code to go through all excel files and add a string (_zop1, _zop2 etc) to their filename. The problem is that this only works in one folder and does not go through the sub folders. I have tried to add various pieces of code from around the web to make it recursive...to no avail.

All help appreciated. Many thanks.

S






Sub test2()

Dim strFolder As String
Dim strFile As String

strFolder = "Z:\Teams\LEAN Wave 3 Document Store\Transmission Project\test\"
lcv = 1
strFile = Dir(strFolder & "\*.*")
Do While Len(strFile) > 0
If InStr(strFile, ".xls") > 0 Then
Name strFolder & strFile As strFolder & Replace(strFile, ".xls", "_zop" & lcv & ".xls")
lcv = lcv + 1
End If
strFile = Dir()
Loop


End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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