Excel VBA- Mass rename all files in a folder based on Cell A2

TheHack22

Board Regular
Joined
Feb 3, 2021
Messages
121
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi All,

Below is a example of daily downloaded files(somedays are > 30) which I manually placed in a folder.
The downloaded files names are not useful (Screenshot). I have been "manually renaming" and saving using the below VBA. I do not need to make a copy of these files, just needs to rename them.Cell A2 usually have the correct name.
I would typically open and click on eack file to make it the Activeworkbook, then run the below code.

Was wondering if there is a way to loop through each file and rename them based on cell A2.

Sub FileNameAsCellContent()
Dim FileName As String
Dim Path As String
Application.DisplayAlerts = False
Path = "C:\Users\C-TL\Box\Amp_Page_Views\Data\"

FileName = Application.Trim(Range("A2").Value) & ".xlsx"
ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub

1632841780255.png

Imran
Quote Reply
Report Edit
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
It is possible but you can't rename all files to 1 name.
 
Upvote 0
It is possible but you can't rename all files to 1 name.
@JEC
Thanks for your response. I need to rename each file to reflects its own name, that's contained in Cell A2 in each file.
Each file name would be different. My apologies for the confusion / been too vague.
Imran
 
Upvote 0
A better way is to list your specific files in a new file. The new name behind the files and loop through that range. Then rename one by one, if you understand what I mean.
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top