Solved

Create and Name a folder from .xls file

Posted on 2013-02-04
5
177 Views
Last Modified: 2013-02-05
I want to create a group of folders based off a excel file.  example:  There is an .xls file with a list of names (sue.smith, joe.blow,  Peter.Johnson)  I would like to create 3 folders with those being the names of the folder.

I suppose it could take a .csv file too...
0
Comment
Question by:und-josh
  • 3
5 Comments
 
LVL 16

Accepted Solution

by:
terencino earned 475 total points
Comment Utility
Hey und-Josh, here is a script to create those folders for you. After adding the macro to your workbook, add a reference to Microsoft Scripting Runtime, select the cell with the folder names you want, then run the CreateFolders macro. It will show a dialog to ask you for a top-level folder where the new folders will be created under.
Hope it helps
...Terry
Sub CreateFolders()
' Add reference to Microsoft Scripting Runtime
Dim c As Range, fso As FileSystemObject, TopLevelFolder, lngCount As Long
Set fso = New FileSystemObject
With Application.FileDialog(msoFileDialogFolderPicker)
  .AllowMultiSelect = False
  .Title = "Select top level folder..."
  .Show
  For lngCount = 1 To .SelectedItems.Count
    TopLevelFolder = .SelectedItems(lngCount)
  Next lngCount
End With

Debug.Print TopLevelFolder
For Each c In Selection
  If c.Value = "" Then GoTo Skip
  fso.CreateFolder TopLevelFolder & "\" & c.Value
Skip:
Next c
End Sub

Open in new window

CreateFolders.xlsm
0
 
LVL 16

Expert Comment

by:terencino
Comment Utility
In case you have Excel 2003, here is the XLS file. And what was that about CSV?
CreateFolders.xls
0
 
LVL 7

Expert Comment

by:karunamoorthy
Comment Utility
0
 
LVL 16

Expert Comment

by:terencino
Comment Utility
I added some code to exit the sub in case you cancelled the dialog box
CreateFolders.xls
0
 

Author Closing Comment

by:und-josh
Comment Utility
THis is Exactly what I was looking for....thanks for the Macro.  My VB script is a bit rusty.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now