dfstoepfel
New Member
- Joined
- Jul 18, 2014
- Messages
- 10
Hello all,
I've searched and searched and can't seem to find a solution, at least not one I can understand. I have a spreadsheet with a list of names and what I'd like to do is have a macro create a folder and a few subfolders for each name I highlight. I found the macro below, that does half of what I want it to do. If I save the spreadsheet in the folder where I want the new folders created, then highlight the cells with the names I want and run the macro, I'll get a list of folders properly named from the highlighted cells. That part is great, however I'd also like to have 5 subfolders created within each new folder, all at the same level. All of the subfolders will be the same each time, for example (apple, pear, orange, banana, lemon) in each named folder. So I can either enter them somewhere on the spreadsheet so the macro can grab them or if they can just be in the macro code, that would be great. Any help would be appreciated.
Sub CreateFolders()
'create the folders where-ever the workbook is saved
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub
I've searched and searched and can't seem to find a solution, at least not one I can understand. I have a spreadsheet with a list of names and what I'd like to do is have a macro create a folder and a few subfolders for each name I highlight. I found the macro below, that does half of what I want it to do. If I save the spreadsheet in the folder where I want the new folders created, then highlight the cells with the names I want and run the macro, I'll get a list of folders properly named from the highlighted cells. That part is great, however I'd also like to have 5 subfolders created within each new folder, all at the same level. All of the subfolders will be the same each time, for example (apple, pear, orange, banana, lemon) in each named folder. So I can either enter them somewhere on the spreadsheet so the macro can grab them or if they can just be in the macro code, that would be great. Any help would be appreciated.
Sub CreateFolders()
'create the folders where-ever the workbook is saved
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub