How to Rename Multiple Files using Macros (VBA) in Excel 365?
Tags: macrosvba, renamemultiplefilesu, vbamacros
Published: 2021-03-06 11:57:02

---
title: How to Rename Multiple Files using Macros (VBA) in Excel 365?
published: true
date: 2021-03-06 10:01:54 UTC
tags: MacrosVBA,Renamemultiplefilesu,VBAMacros
canonical_url: https://geekexcel.com/how-to-rename-multiple-files-using-macros-vba-in-excel-365/
---

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**.

![Excel Files](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_mxSfc9JPKz.png)<figcaption id="caption-attachment-22302">Excel Files</figcaption>

- 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.

![Enter file names](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_powkzrcVaC.png)<figcaption id="caption-attachment-22303">Enter file names</figcaption>

- On the **Developer Tab, select** the **Visual Basic** option under the **Code** section.

![Select Visual Basic option](https://geekexcel.com/wp-content/uploads/2020/09/Select-Visual-Basic-option-4.png)<figcaption id="caption-attachment-14755">Select the Visual Basic option</figcaption>

- 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.**

![Save the code](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_27RufXJPBy.png)<figcaption id="caption-attachment-22305">Save the code</figcaption>

- You have to open the sheet containing the data. On the **Developer Tab, choose** the **Macros option** in the **Code** section.

![Choose the Macros option](https://geekexcel.com/wp-content/uploads/2020/09/Choose-the-Macros-option-2.png)<figcaption id="caption-attachment-14747">Choose the Macros option</figcaption>

- You need to make sure that your macro is selected and **click** the **Run** button.

![Click the Run button](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_Ntrby5YWv0.png)<figcaption id="caption-attachment-22306">Click the Run button</figcaption>

- 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.

![Hit the OK button](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_lLbMjvsKgl.png)<figcaption id="caption-attachment-22307">Hit the OK button</figcaption>

- Finally, you can go to that directory and see if the file names are changed or not.

![Output](https://geekexcel.com/wp-content/uploads/2021/03/explorer_B94FJPktDL.png)<figcaption id="caption-attachment-22308">Output</figcaption>

## 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.](https://geekexcel.com/)** Keep Learning!

#### Read Ahead:

- [Split Data into Multiple Worksheets with Set of Rows using Macros (VBA) in Excel!!](https://geekexcel.com/split-data-into-multiple-worksheets-with-set-of-rows-using-macros-vba-in-excel/)
- [Hide Rows with Zero Value using Macros (VBA) in Excel Office 365!](https://geekexcel.com/hide-rows-with-zero-value-using-macros-vba-in-excel-office-365/)
- [Merge Multiple Cells into One Cell using Macros (VBA) in Excel 365!!](https://geekexcel.com/merge-multiple-cells-into-one-cell-using-macros-vba-in-excel-365/)