On Oct 23, 2:14 pm, "Rick Rothstein \(MVP -
VB\)"
wrote:
Are you executing the subroutine from the correct Sheet's code window?
Alternately, you could qualify the Range objects location with
Worksheets("Sheet1") or the like.
Rick
wrote in message
ups.com...
Rick,
To test, I have 11 folders in c:\test directory and an excel file with
A1 to A11 cells with values. I am using the following code. I dont see
the folders getting renamed. Am I missing something? Thanks
Sub RenameFolders()
Dim X As Long
For X = 1 To 11
If Dir("C:\test" & CStr(X) & "\", vbDirectory) < "" And _
Trim(Range("A" & CStr(X)).Value) < "" Then
Name "C:\test" & CStr(X) As "C:\" & Range("A" & CStr(X)).Value
End If
Next
End Sub
On Oct 23, 12:36 pm, "Rick Rothstein \(MVP - VB\)"
wrote:
Okay, I have 40 folders named 1, 2, 3, 4... 40.. The folders are in
C:
The folder named 1 should be renamed by the text/value in cell A1.
The folder named 2 should be renamed by the text/value in cell A2.
This macro should do that...
Sub RenameFolders()
Dim X As Long
For X = 1 To 40
If Dir("C:\" & CStr(X) & "\", vbDirectory) < "" And _
Trim(Range("A" & CStr(X)).Value) < "" Then
Name "C:\" & CStr(X) As "C:\" & Range("A" & CStr(X)).Value
End If
Next
End Sub
You do realize this will only work once, right? I mean, after you run it,
there will be no folders left with the names 1, 2, 3, etc. against which
you
could run the macro.
Oh ya..
Rick- Hide quoted text -
- Show quoted text -
Rick, I am using the subroutine in a module and I call the subroutine
by clicking command button.
Now I am getting Path/File access error. Can you please send the excel
file (the one you have tried writing the code for me) you have to
Thanks
Private Sub CommandButton1_Click()
Call RenameFolders
End Sub
In a module I have this:
Sub RenameFolders()
Dim X As Long
For X = 1 To 11
If Dir("C:\test\" & CStr(X) & "\", vbDirectory) < "" And _
Trim(Worksheets("Sheet1").Range("A" & CStr(X)).Value) < ""
Then
Name "C:\test\" & CStr(X) As "C:\test\" &
Worksheets("Sheet1").Range("A" & CStr(X)).Value
End If
Next
End Sub