Create Folders in Directory with Excel VBA?

  • Thread starter Thread starter Jrew23
  • Start date Start date
J

Jrew23

Hi,

Is there a way to create folders with a specfic names, and have them
saved in a directory. I have an excel file with 250 records with my
desired folder names.

I want to avoid having to through the process of selecting <File | New
| Folder> then naming the folder -- 250 times!

I imagine there's an easier way with VBA... please help!

Thanks
 
It can be done something like this. Attatch code to a command button on the
sheet.
Alter code to suit your reqirements. Test on a dummy workbook first until
you get it to work the way you want.

Please note that there are practical limits in windows in the number of
subfolders that can be created in a folder etc.
You may run into problems with 250 in the same subfolder.


Private Sub CommandButton1_Click()

' assuming names are all legal characters.
On Error Resume Next
ChDrive "c" ' make sure you are on the drive you want be
ChDir "\" ' make sure you are in the root dir
ChDir "demo" ' change to the dir you want the folders created in

For i = 10 To 15 ' loop thru the cells with the names (assumes col E rows 10
to 15)
MkDir Worksheets("sheet1").Cells(i, "e")
Next i

End Sub


HTH

Ken
 
Take a look at mkdir in VBA's help.
Hi,

Is there a way to create folders with a specfic names, and have them
saved in a directory. I have an excel file with 250 records with my
desired folder names.

I want to avoid having to through the process of selecting <File | New
| Folder> then naming the folder -- 250 times!

I imagine there's an easier way with VBA... please help!

Thanks
 
(e-mail address removed) wrote...
you should use Access; it works better; and it wont crap out at 64k
rows lol

Another example of the wrong tool for the task.

Making directories is an OS task for which neither Excel nor Access
provide built-in support. Both would need to use VBA.

Better by far would be creating the folder listing as a text file, then
using the GnuWin32 xargs command to process each line in the file as
the name of a folder to create.

USE THE BEST TOOL FOR THE TASK.

But let's assume the OP doesn't have xargs or any other scripting
language other than Excel. What's needed in Excel/VBA?

Sub md()
Dim c As Range
If Not TypeOf Selection Is Range Then Exit Sub
For Each c In Selection
Mkdir c.Value
Next c
End Sub

which allows the user to select the folders to create by selecting
cells in a worksheet.

Access can handle more than 65535 records, but no sane person would use
either Excel or Access to create that many or more folders. Oops, that
could imply you might!

Anyway, oh great sage, how to do this in Access? Details, not more BS!
 
Back
Top