+ Reply to Thread
Results 1 to 5 of 5

Create Folders in Directory with Excel VBA?

Hybrid View

  1. #1
    Jrew23
    Guest

    Create Folders in Directory with Excel VBA?

    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


  2. #2
    Ken Macksey
    Guest

    Re: Create Folders in Directory with Excel VBA?

    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



  3. #3
    Dave Peterson
    Guest

    Re: Create Folders in Directory with Excel VBA?

    Take a look at mkdir in VBA's help.

    Jrew23 wrote:
    >
    > 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


    --

    Dave Peterson

  4. #4
    aaron.kempf@gmail.com
    Guest

    Re: Create Folders in Directory with Excel VBA?

    you should use Access; it works better; and it wont crap out at 64k
    rows lol


  5. #5
    Harlan Grove
    Guest

    Re: Create Folders in Directory with Excel VBA?

    aaron.kempf@gmail.com 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!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1