Renaming files using excel

sanilmathews

Board Regular
Joined
Jun 28, 2011
Messages
102
Hi,

I am trying to write VBA code to rename files (word doc) in a particular folder.
Please help me with the code to rename files in the folder by referring a column in the excel.

For example: Column A has a list of names aaa, bbb, ccc, ddd in A1, A2, A3, A4 etc.... I need a code to rename the existing files which are saved already in a different name with the new name listed in A1, A2, A3, A4 etc....

I would appreciate if you could give me a better solution ASAP!!
Thanks in advance:)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
OK well something like this (I am freetyping here so it may need debugging)

Code:
Sub RenameMyFiles()
Dim X as long
Dim DirName as string
DirName = "C:\Temp\" 'Change this to your file location
For X = 1 to range("B" & Rows.count).end(xlup).row 'Change the 1 to a 2 if you have a header
name DirName & Range("B" & X).text & ".doc" as DirName & Range("A" & X).text & ".doc" 'Change .doc to what you need (maybe docx depending on version)
Next
End sub
 
Upvote 0
Hey,

I'm in an urgent need of an Excel macro that enables me to rename all files in a folder AND put these renamed files in a separate folder.

Can you please mail me this macro of yours on - henanksha@gmail.com

Any help will be much appreciated.

Cheers
 
Upvote 0
Just put a dir name in the name part

name "c:\myfile.xls" as "c:\NewFolder\AnotherFolder\MyNewFilename.xls" will rename and move the file.
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

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