This post will guide you to know the simple steps to rename multiple files using Macros (VBA) in Excel Office 365. Macros and VBA are really helpful to achieve any kind of task with a few clicks. Let’s see the simple instructions to finish the task quickly.
Rename Multiple Files using Macros:
If you want to rename multiple files in Excel, do as follows.
- Let us assume that you have multiple files and format for all file names like excel1.xlsx , excel2.xlsx , excel3.xlsx , excel4.xlsx.
- We are going to rename all those files to another format.
- To do this, you need to type all the file names into your current worksheet, then create a new column that contains a new file name list.
- On the Developer Tab, select the Visual Basic option under the Code section.
- Then you need to copy and paste the code given below.
VBA code to rename files using Macros
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(“B1:B4”), 0)
If curRow > 0 Then
Name selectDirectory & Application.PathSeparator & dFileList As _
selectDirectory & Application.PathSeparator & Cells(curRow, “D1:D4”).Value
End If
dFileList = Dir
Loop
End If
End With
End Sub
- You need to save the code by selecting it. Then close the window.
- You have to open the sheet containing the data. On the Developer Tab, choose the Macros option in the Code section.
- You need to make sure that your macro is selected and click the Run button.
- Now, you need to select one directory that contains files you want to rename in the Browser dialog box
- Then, you have to click the OK button.
- Finally, you can go to that directory and see if the file names are changed or not.
Closure:
In this post, you can clearly learn the simple instructions to rename multiple files using Macros (VBA) in Excel Office 365. Kindly, give your feedback in the below comment section. Thanks for visiting Geek Excel. Keep Learning!
Top comments (0)