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
 

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,731
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
 

nip251

New Member
Joined
Jul 9, 2010
Messages
7
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
 

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,731
OK I never tried that and it didn't work.

Try this. Works well.
http://www.experts-exchange.com/Software/Office_Productivity/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
 

Forum statistics

Threads
1,082,042
Messages
5,362,816
Members
400,694
Latest member
Sofie17

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top