rename bunch of csv files at one go

nip251

New Member
Joined
Jul 9, 2010
Messages
7
i am new to macro hence i need your help
i have mote than 3000 csv files in one folder ie in d:\re
I want to change name of those files

I also have one excel file containing OLD and NEW names in colomun A and B
like
A, B
Old Name, New Name
asd, bu_09943_n
sdc ,BU_43434_b
lt b ,u_22222_n
mm ,bu_2222_n

like this
now i want to change all thies names at on go can any one write the macro for me ? PLEASE
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi,

got this code from the archives of this site:
http://www.mrexcel.com/archive/VBA/11962.html:

Code:
Sub RenameFiles()
For I = 1 to Range("A1").End(xlDown).Row
OldFileName = Cells(R,1).Value
NewFileName = Cells(R,2).Value
If Not Dir(OldFileName) = "" Then Name OldFileName as NewFileName
Next
End Sub
 
Upvote 0
thanks,
but i still not able to do, can you write more on this so i can copy the program in excel macro
please , Thnak you again
 
Upvote 0
OK I never tried that and it didn't work.

Try this. Works well.
http://www.experts-exchange.com/Sof...Office_Suites/MS_Office/Excel/Q_23140028.html


Code:
Sub RenameFiles()
   Dim lngRow As Long, lngRowCount As Long, lngStartRow As Long
   Dim strPath As String
   On Error Resume Next
   strPath = "D:\re"    '---------------------------------as required
 
   If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
   lngRowCount = Cells(65536, "A").End(xlUp).Row
   lngStartRow = 1
   Application.ScreenUpdating = False
   For lngRow = lngStartRow To lngRowCount
      If Len(Cells(lngRow, "A").Value) > 0 And Len(Cells(lngRow, "B").Value) > 0 Then
         Name strPath & Cells(lngRow, "A").Value As strPath & Cells(lngRow, "B").Value
         Cells(lngRow, "C").Value = "Renamed"
      End If
   Next lngRow
   Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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