-1

I've been working on a code to rename thousands of folders within a parent folder. Here is what I have so far -- I'm not entirely sure where to put what or what codes to use.

I have an excel file set up where Column B is the old file source and Column C is the new file source.

How do I code this into the VBA?

Sub FolderRename()
'Declaring variables
Dim complete_pathof_folder As String, state As String
For i = 2 To Sheets("Rename File").Range("b2").End(x1Down).Row
'Variable values
complete_pathof_folder = Cells(i, 2)
state = Cells(i, 5)

'Renames Original Folder Name
Name "C:\Users\n0269632\Desktop\Customers\AFL TELECOMMUNICATIONS"  
As "C:\Users\n0269632\Desktop\Customers\AFL TELECOMMUNICATIONS (SC)"
Next i

'Repeats Code Until an Empty Cell is Reached
Do Until IsEmpty(Cells(iRow, 1))
dCellValues(iRow) = Cells(iRow, 2).Value
iRow = iRow + 1
Loop
End Sub
0m3r
  • 12,286
  • 15
  • 35
  • 71
  • http://stackoverflow.com/questions/30916732/vba-code-to-rename-1000s-of-folders?rq=1 – Ken White Jun 19 '15 at 14:05
  • possible duplicate of [How do I write a VBA code to rename all folders under a root folder?](http://stackoverflow.com/questions/30892816/how-do-i-write-a-vba-code-to-rename-all-folders-under-a-root-folder) – rohrl77 Jun 19 '15 at 14:07
  • 2
    Nick, unless you try to learn, asking the same question over and over is just going to get people upset and waste time. You need to try to do some sort of tutorial or actually try what people are suggesting as the other questions have answers that do exactly what you have asked, and the responders seemed more than willing to answer any follow-up questions you had. – OpiesDad Jun 19 '15 at 14:11

1 Answers1

0

You've put the original folder name into a variable (complete_pathof_folder), so put the new folder name into a variable the same way:

newfolderpath = cells(i,3).  

Then you just want to use these variables in the Name statement:

 Name complete_pathof_folder As newfolderpath

You probably want to do some error checking such as:

  If Dir(complete_pathof_folder) <> "" Then
           Name.....
  End If

Otherwise, the code will throw an error if a path in the list doesn't exist.

OpiesDad
  • 3,385
  • 2
  • 16
  • 31