Hi,
I have the code below that does a good job of renaming folders but it only renames one subfolder down in the folder '2023 Test' and I need it to rename files in all the sub-subfolders where they occur.
As you can see I currently specify the folder name in cell D4 then run the code and have to do it for all the folders that have subfolders. Can this be tailored so I can rename all files in the folder '2023 Test' capturing all folders, subfolders and sub-subfolders at once? Note - some folders in '2023 Test' have subfolders and some don't.
I have the code below that does a good job of renaming folders but it only renames one subfolder down in the folder '2023 Test' and I need it to rename files in all the sub-subfolders where they occur.
As you can see I currently specify the folder name in cell D4 then run the code and have to do it for all the folders that have subfolders. Can this be tailored so I can rename all files in the folder '2023 Test' capturing all folders, subfolders and sub-subfolders at once? Note - some folders in '2023 Test' have subfolders and some don't.
VBA Code:
Dim fso As Object, fold As Object, fFile As Object
Dim fPath As String, fName As String, newName As String
fPath = "C:\Users\Chris\Desktop\2023 Test\" & Range("D4").Value
cnt = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fold = fso.GetFolder(fPath)
For Each fFile In fold.subFolders
cnt = ""
fName = Dir(fFile.Path & "\*Presentation.pptx", vbNormal) 'the files to rename
Do While fName <> ""
newName = "\Test" & ".pptx" 'the new name and file association
Name fFile.Path & "\" & fName As fFile.Path & newName
fName = Dir
cnt = cnt & "i" 'just in case there is more than 1 file in a folder
Loop
Next
End Sub