VBA Creating Folders based a list of names

Good Afternoon Experts

I am trying to find a way to create folders in a directory based upon a list of names for the folder name.

Hope you can help
Nick CollinsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITguy565Commented:
@nick,

Try this :

VBA - Create folders based on names on a column

Published by jppinto on 23.3.10 / Tags: VBA

This is a simple thing that sometimes we need to use. We have an Excel sheet that has a list of, for example, names in column A and we want to create folders for each of them on a disk. For that we can make a small VBA code to go through each of the rows on column A and create a folder with that name on the path that we specify on our code. To do that, I came up with this code:
Sub MakeFolders() 
    Dim xdir As String 
    Dim fso 
    Dim lstrow As Long 
    Dim i As Long 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row 
    Application.ScreenUpdating = False 
    For i = 1 To lstrow 
        'change the path on the next line where you want to create the folders 
        xdir = "C:\" & Range("A" & i).Value 
        If Not fso.FolderExists(xdir) Then 
            fso.CreateFolder (xdir) 
        End If 
    Next 
    Application.ScreenUpdating = True 
End Sub

Open in new window

On this example, I will create the folders under C:\ If you want a different place, just change it on the code.

reference :
http://www.excel-user.com/2010/03/create-folders-based-on-names-on-column.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewCommented:
VBA feels like overkill to me, but maybe there is more going on than I know.  Here's a simple BAT script approach.  Create a file called file.txt and place the folder names to create one per line (not the full path, just the name of the folder).  Adjust the SETs in this BAT and give it a run from a command prompt where the TXT file is.

@echo off
setlocal

set BaseDir=c:\basedir
set ListFile=list.txt

for /f "usebackq tokens=*" %%A in ("%ListFile%") do (
    if exist "%BaseDir%\%%~A" (
        echo Folder already exists: "%BaseDir%\%%~A"
    ) else (
        mkdir "%BaseDir%\%%~A"
    )
)

Open in new window


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.