Skip to main content

How to rename multiple files of a folder in Excel?

May be most of us are suffered with this problem that we need to rename multiple files in a folder, to rename the filenames one by one will make us crazy if there are hundreds or thousands files in that folder. Are there any good functions for us to deal with this task?

List all file names from a specific folder in worksheet with kutools for Excel

Rename multiple files of a folder in Excel with VBA code


If there are multiple files that you want to rename, first, you can list the old file names in a column of worksheet, and then enter the new filenames that you want to replace with. To quickly list all files in worksheet, you can use the Kutools for Excel’s Filename List utility.

After installing Kutools for Excel, please do as follows:( Free Download Kutools for Excel Now )

1. Click Kutools Plus > Import & Export > Filename List, see screenshot:

2. In the Filename List dialog box, click doc-rename-multiple-files-1 button to choose the file folder that you want to list the files, and then click All files from the Files type, see screenshot:

doc-rename-multiple-files-1

3. Then click OK button, all the filenames have been list in a column of a new worksheet, as well as some file attributes, and now, you can delete other unwanted columns and only leave the File Name column, see screenshot:

doc-rename-multiple-files-1

Click to know more about this Filename List feature…

Free Download Kutools for Excel Now


After listing all original filenames in one column A, and you should type new filenames in column B as following screenshot shown:

doc-rename-multiple-files-1

And here I will talk about a VBA code which may help you to replace the old filenames with the new filenames at once. Please do with following steps:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications Window.

2. Click Insert > Module, and paste the following macro in the Module window.

VBA code: Rename multiple files in a folder

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

3. After pasting the code, please press F5 key to run this code, and in the Browse window, select the folder which you want to change the filenames in, see screenshot:

doc-rename-multiple-files-1

4. And then click OK, all the old filenames have been replaced by the new filenames immediately. See screenshots:

doc-rename-multiple-files-1  2 doc-rename-multiple-files-1

Notes:

1. When you list your old and new filenames, the file extension must be included.

2. In the above code, the reference A:A indicates the old filenames list you want to rename, and reference B contains the new filenames that you want to use, you can change them as your need


Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Related articles:

How to create sequence worksheets from a range of cells in Excel?

How to rename multiple worksheets in Excel?

Best Office Productivity Tools

Supports Office/Excel 2007-2021 and 365  |  Available in 44 Languages  |  Easy to Uninstall Completely

Popular Features: Find/Highlight/Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns     Move Columns   |   Unhide Columns   |   Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...

Supercharge Your Excel Skills: Experience Efficiency Like Never Before with Kutools for Excel  (Full-Featured 30-Day Free Trial)

kte tab 201905

60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day! (Full-Featured 30-Day Free Trial)
60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 
 
Comments (37)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
The above stated code does not detect native language file names in Hindi or Marathi - example "HIN-MALE-CH - 7 - कार"
Here the code does not detect "कार"
Any way to handle this issue?
This comment was minimized by the moderator on the site
Sziasztok!
Ha kép nevébe "/" jelet akarok rakni, akkor min kell változtatnom?
Ha benne van a "/" jel akkor nekem nem működik.

Köszönöm
Andor
This comment was minimized by the moderator on the site
Hello, Benedeczki,

Under normal circumstances, the file name cannot contain the /\:*?<>” symbol, so if your picture name contains the / symbol, the code cannot run normally.
You'd better to remove the / symbol from the file name.
Thank you!
This comment was minimized by the moderator on the site
wow, useful and very helpful. BIG THANKS :)
This comment was minimized by the moderator on the site
Sub RenameMultipleFiles()
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
selectDirectory = .SelectedItems(1)
dFileList = Dir(selectDirectory & Application.PathSeparator & "*")

Do Until dFileList = ""
curRow = 0
On Error Resume Next
curRow = Application.Match(dFileList, Range("A:A"), 0)
If curRow > 0 Then
Name selectDirectory & Application.PathSeparator & dFileList As _
selectDirectory & Application.PathSeparator & Cells(curRow, "B").Value
End If

dFileList = Dir
Loop
End If
End With
End Sub

this formula does not rename1st document
This comment was minimized by the moderator on the site
Love this so much! Is there a way to use Kutools to edit metadata tags for music similar to this with filenames? Would love being able to mass edit song tags through Excel rather than on iTunes or other third party song tag editors. Thank you!
This comment was minimized by the moderator on the site
okay Thank you
This comment was minimized by the moderator on the site
Hello. I did this for a couple of files and it worked successfully. The next few files i tried, did not work. There were a few formulas added to the new names, could that be the issue?
This comment was minimized by the moderator on the site
Very helpful. Thank you!
This comment was minimized by the moderator on the site
great, worked great for me
This comment was minimized by the moderator on the site
Thank you so much for your information. It was really nice!
This comment was minimized by the moderator on the site
Hi there
It does not work with unicode file names. How can it be done fine?
This comment was minimized by the moderator on the site
Hi,

I'm trying to use the code for renaming the non extension files to files with extension. it doesn't work. It works fine with files which have extension already.

Thanks
Jay
This comment was minimized by the moderator on the site
Thank you so much...
This comment was minimized by the moderator on the site
Hello, some of the files have same name. Scripts skip those files. Is there a way to modify the script so it adds a number 1, 2, 3 and so on for every duplicate name?
This comment was minimized by the moderator on the site
Hello, Kay,
To rename the files based on duplicate new names with name-1,name-2, the following VBA code may help you, please try it.

Note: After pasting this code, you should reference the Microsoft Scripting Runtime option in the References-VBAProject dialog box as below screenshot shown.

Sub RenameFiles()
Dim xDir As String
Dim xFile As String
Dim xVal As String
Dim xRow As Long
Dim xCount As Long
Dim xTemp As Long
Dim xDictionary As New Dictionary
Application.ScreenUpdating = False
On Error Resume Next
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
xDir = .SelectedItems(1)
xFile = Dir(xDir & Application.PathSeparator & "*")
Do Until xFile = ""
xRow = 0
xRow = Application.Match(xFile, Range("A:A"), 0)
If xRow > 0 Then
xCount = 0
xVal = Cells(xRow, "B").Value
If Not xDictionary.Exists(xVal) Then
xDictionary.Add xVal, xCount
Else
xDictionary.Item(xVal) = xDictionary.Item(xVal) + 1
xTemp = InStrRev(xVal, ".")
Cells(xRow, "B").Value = Mid(xVal, 1, xTemp - 1) & "-" & CStr(xDictionary.Item(xVal)) & Mid(xVal, xTemp)
End If
Name xDir & Application.PathSeparator & xFile As _
xDir & Application.PathSeparator & Cells(xRow, "B").Value
End If
xFile = Dir
Loop
End If
End With
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
I am following the same process but couldn't succeeded in renaming the file i am also changing ("A:A") and ("B"). Is there any other valuve which i need to change in the code
This comment was minimized by the moderator on the site
I cant understand with range ( A:A) or (B) how to define that, thank you
This comment was minimized by the moderator on the site
Hi, Dee,

As the note remind, the reference A:A indicates the old filenames list you want to rename, and reference B contains the new filenames that you want to use
, as following screenshot shown:

Hope this can help you, thank you!
This comment was minimized by the moderator on the site
I would like to rename multiple files from folders and subfolders. So im thinking a VBA code there looks at the path there is in the Column 'Containing Folder' (I Check the checkbox 'Include files in subdirectories') I am no where near good enough for coding VBA, but i look and try to understand. Thanks
This comment was minimized by the moderator on the site
This is game changing. Thank you SO MUCH!!!
This comment was minimized by the moderator on the site
To rename the multiple files you can also check a software. Search on google- BatchRenameFiles Tool. Check the first search result.


Thanks
Jonathan F.
This comment was minimized by the moderator on the site
hi, Amazing codes, has saved my hell lot of time.. thanks a ton..
This comment was minimized by the moderator on the site
i want to make combo of pictures for example i have 33 images and i want to create a combo of pictures with each other, please find attched i have 10000 more images so that i can create in a 1 click of multiple images. please call or email at
This comment was minimized by the moderator on the site
I suggest to try KrojamSoft BatchRename
This comment was minimized by the moderator on the site
I tried it for excel, it changes file type.Can you please provide me code for csv files rename.
This comment was minimized by the moderator on the site
Dear all, Try KrojamSoft BatchRename for batch rename the files its very easy to use.
This comment was minimized by the moderator on the site
Thank you so much sir, God bless you!
This comment was minimized by the moderator on the site
Hi, I have more than 100 excel files which I have downloaded from a system and kept in the folder. All these files has a sheet named as Content. I want these excel files to be named using the text that is available in the Cell AA2 of the respective Content sheet. Such that the name in this Cell AA2 will be exactly the File name of that respective Excel file. all the files in the folder should get renamed in the same way. Please suggest a macro that can work in this way.
This comment was minimized by the moderator on the site
Hi. Is your task already Solved. ? I can help if still unsolved. Pls mail me your task. Tx Franz
This comment was minimized by the moderator on the site
I successfully used the above instructions last year to rename files in half-a-dozen folders. It worked so well that I saved the instructions for future use. I've recently tried to use it again, but after pasting the macro above in the Module window when I hit F5 instead of getting a browser window to select the desired folder, I get a new dialog box prompting me for a Macro name. Any suggestions? I usually have about 3-4 times a year where I need to rename files this way, and I was very excited when it worked last year.
This comment was minimized by the moderator on the site
Is it possible rename just a piece of a file name without declaring the full file name and extension in the excel sheet? i.e. change 123-yz.jpg to abc-yz.jpg but I only know that 123 needs changing to abc on every image in the folder?
This comment was minimized by the moderator on the site
Surprised (a little) to see someone use the same syntax for naming vars (xDir, for example). It allows for exceptionally well named vars that don't conflict with system names (e.g., Dir or Date). I also use 'z' for global functions (e.g., zMsg, that returns true or false rather than vbOK or vbCancel) and 'y' for constants (e.g., yCR for vbNewline and yCR2 for two of them). Good work and good thinking on your part. You must be very smart!
This comment was minimized by the moderator on the site
How to rename files which contains chinese characters in name. Please help on it
This comment was minimized by the moderator on the site
Nevermind, i figured it out. Thanks. " xRow = Application.Match(xFile, Range("C:C"), 11)"
This comment was minimized by the moderator on the site
What do i need to modify in the code above if my old and new names do not start until Row 11. I changed this line "xRow = Application.Match(xFile, Range("C11:C5000"), 0)" but it didn't work.
This comment was minimized by the moderator on the site
Dear all, How can I change FOLDERS the same way as shown above? Could you kindly help me with this issue? The question is: How to rename multiple FOLDERS of a folder in Excel? Kind regards!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations