Last active
May 20, 2020 22:48
-
-
Save bhandarisaurav/37d99c37a3c5ba298d46fe7c811d6282 to your computer and use it in GitHub Desktop.
Macro code to Rename all files in a folder with the new names on Excel sheet!!!. List all original filenames in one column A, and you should type new filenames in column B. Then press ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications Window. Now paste this code and press F5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub RenameFiles() | |
'Updateby20141124 | |
Dim xDir As String | |
Dim xFile As String | |
Dim xRow As Long | |
With Application.FileDialog(msoFileDialogFolderPicker) | |
.AllowMultiSelect = False | |
If .Show = -1 Then | |
xDir = .SelectedItems(1) | |
xFile = Dir(xDir & Application.PathSeparator & "*") | |
Do Until xFile = "" | |
xRow = 0 | |
On Error Resume Next | |
xRow = Application.Match(xFile, Range("A:A"), 0) | |
If xRow > 0 Then | |
Name xDir & Application.PathSeparator & xFile As _ | |
xDir & Application.PathSeparator & Cells(xRow, "B").Value | |
End If | |
xFile = Dir | |
Loop | |
End If | |
End With | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment