• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 31
  • Last Modified:

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
0
Nick Collins
Asked:
Nick Collins
2 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now