Renaming lots of folders different names...

Dan1000

Board Regular
Joined
Nov 4, 2006
Messages
210
Is there a short cut to renaming lots of folders under one folder?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Is there a logical pattern to or connection between the new/old names?

Do you have a list in an excel spreadsheet maybe?

Folders can be renamed programmatically in a number of ways, so long as none of the files in them are open.
 
Upvote 0
No connection
...create folders then rename the folders to different folder names. The folder list is likely to be large (500 different folder names plus).
 
Upvote 0
So you want to make a set of new folders within a pre-existing folder?

If so, the following code might help

Code:
Sub makeFolders()
    mainfolder = "c:\testfolder\"
    For Each cel In ActiveSheet.Range("A1", Cells(Rows.Count, "A").End(xlUp))
        MkDir mainfolder & cel.Value
    Next
End Sub

If you set mainfolder to the location you want all your new folders to be created and create a sheet where column A contains a list of the folder names, then this will create those folders.
There's no error checking, so if there are any characters that aren't allowed in file names, it'll fall over.
Test it in a testfolder like mine to make sure it does what you want.
 
Last edited:
Upvote 0
This didn't work for me. I named a folder "testfolder" on my desktop, then I added test spreadsheet on the desktop with a list of names in A. I tried to run the macro to create folders in the testfolder with all the names, but I get a path not found error or a run time error. What's that about?
 
Upvote 0
excelR8R

have you tested this? Debug launches indicating an error in 'MkDir mainfolder & cel.Value' line,

regards
 
Upvote 0
Checked through more thoroughly and found one or two errors...space in folder name ie 'test folder' and duplicate names in list. Code is sensitive...is there any error checking code that can be included? and can this code be made to create folders from more than one list of names at a time?

Regards
 
Upvote 0

Forum statistics

Threads
1,203,075
Messages
6,053,393
Members
444,661
Latest member
liamoohay

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