View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Macro to assign cell values as folder name

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