KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 458
- Office Version
- 2016
- Platform
- Windows
Hello everyone
Anyone who can help, I use this VBA code to rename all files in a folder / subfolder.
Folder in Cell H1
But now I would like the old name to be in column C2 and down and the new name in column D2 and down. The new files must have the same file format as before it was renamed.
Anyone who can help?
Any help will be appreciated
Best Regards
Klaus W
Anyone who can help, I use this VBA code to rename all files in a folder / subfolder.
Folder in Cell H1
But now I would like the old name to be in column C2 and down and the new name in column D2 and down. The new files must have the same file format as before it was renamed.
Anyone who can help?
Any help will be appreciated
Best Regards
Klaus W
VBA Code:
Sub Rename_Files()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As File
Dim new_name As String
Set fo = fso.GetFolder(sh.Range("H1").Value)
For Each f In fo.Files
new_name = Application.VLookup(f.Name, sh.Range("A:c"), 3, 0)
f.Name = new_name
Next
MsgBox "All files renamed successfully!"
End Sub