Excel Macro to Rename Multiple Files in a Folder and Subfolders

Have you ever been in a situation when you’ve got hundreds of Excel files stored in a folder and you need to rename them? Well, there’s a quick and automated solution to rename a bunch of files without going through each one of them.

In this tutorial, we’ll walk you through different methods to batch rename your Excel files.

Rename multiple files in folders and subfolders. Utilize 10+ renaming rules. Also rename files on the Cloud. Use Easy File Renamer today! 

Excel Macros

A Macro is a rule or pattern that specifies how to map a certain input into a preset sequence of output. The intent behind the creation of macros is to avoid repetitive tasks and make complex operations easier.

Macros are popularly used in different professions. For example, software programmers use them to reuse an existing code. In Excel, macros are very popular among financial analysts who use them to generate financial ratios, build portfolios, investment scenarios, etc. Stock market dealers often use macros to monitor price changing patterns, maintain complex trading patterns, build risk management systems, and forecast earnings/ losses.

In contrast to functions, macros are always pre-processed before your program compiles.

Rename Multiple Files in a Folder Using Excel Macros

Method 1: Rename Files with Similar Name Patterns

Here, we assume that your file names have a similar name pattern. You can use this method if your file names have common text with an incremental number. For example, MyFile1.xlsx, MyFile2.xlsx, MyFile3.xlsx, etc.

Steps:

Open Microsoft Excel and create a new WorkBook.

Type the list of all your file names in the folder you want to rename in Column B.

Type the new names for those files in Column D.

Click the Developer tab on the Ribbon interface and then click the Visual Basic icon. Alternatively, you may press Alt + F11.

Excel will launch the Visual Basic Editor window which is mainly split into two parts:

A narrow left part consists of the Project Explorer panel and the Properties panel. In Project Explorer, you’ll see your active WorkBook along with sub-sheets (such as Sheet1, Sheet2, etc)

A wider part on the centre-right lets you view, write and edit the code. 

Type the following code into the Code window:

Click on the Save icon to save your code.

Now click the Run icon on the toolbar to execute your macro.

Excel will display a new dialog with the list of available macros. Select your current macro, and click on Run to confirm execution.

Choose the folders that contain the files you want to rename (for example, C:\Users\XYZ\Documents) and click on OK.

Method 2: Rename Files with Different Name Patterns

Use this method if you need to rename files that have different file name  patterns (existing). In other words, these file names are not common in each other. They’re unique. For example, Taxes.xlsx, Insurance.xlsx, Mortgages.xlsx, etc.

Steps:

Open Excel and create a new WorkBook.

Click on the Insert tab on the Ribbon interface and choose to create a new Table.

Create a table with 2 columns and insert it into the cells binding A and B columns.

In Column A, specify the header name: File Names.

In Column B, specify the header name: New Names.

In the subsequent rows (Cell A2, A3, …), write a list of all files that you want to rename.

In Cell B2, B3, …, write new names for your files.

Press Alt + F11 to open the Visual Basic Editor window.

Type the following code:

Click on the Run icon on the toolbar and confirm your action to execute it.

 

Method 3: Automatically Batch Rename Files Without Macro/ Coding Knowledge (Recommended)

Not everyone has coding knowledge. Sometimes, things may go wrong or you may accidentally alter some important files in an attempt to rename them.

The best way to prevent this dilemma is to use specialized software built to batch rename Excel WorkBooks and other files. Easy File Renamer is an industry-leading solution that provides plenty of file renaming patterns and automates the complete procedure.

Easy File Renamer is your best bet if you’re

  • Not willing to take the risk of losing your data due to incorrect coding/ macros
  • Don’t have the expertise to deal with Excel Macros and advanced Excel tools
  • Looking for a 1-Click solution with a user-friendly interface to get the task done without any hassle
  • Want to perform advanced renaming (insert text, remove text from filenames, replace characters, etc.)
  • Save time
  • Have files with complex file renaming patterns (such as files with similar and different name patterns in the same folder)
  • Want to opt-out certain files from renaming

Steps:

Download Easy File Renamer and install it on your computer.

Exit Microsoft Excel. If your WorkBooks are open, they cannot be renamed while in use.

Open EFR and click on the System Renamer tab.

To add individual files, select the Files option. To add folders, select the Folders option.

Click on Add Files or Add Folders (depending on what you’ve selected earlier), and then select your files/ folders.

EFR will list out all the selected items in the interface along with their full paths.

On the left-hand side, click on Select Rule and choose your desired renaming criteria. Add that rule by clicking the Add Rule option.

Repeat the same procedure to add multiple rules, if required.

Click on the Rename button on the bottom right corner.

EFR will now rename the files within seconds.