Script to create folders and subfolders and their subfolders shows an error

bertmg

New Member
Joined
Apr 9, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
0
I'm attempting to create a 5 level folder having an Excel sheet as the source.
NOTE: Excel sheet is column organized by levels on each column as shown.

Reference VB script from:
Creating folders and sub-folders with a VBA macro

ERR: **'Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))**

Script:

Sub CreateFolderStructure()
Dim objRow As Range, objCell As Range, strFolders As String

For Each objRow In ActiveSheet.UsedRange.Rows
strFolders = "C:\Users\morar\Downloads\FoldersNSubsr"

For Each objCell In objRow.Cells
strFolders = strFolders & "\" & objCell
Next
**Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))**
Next
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
VBA Code:
Option Explicit

Function GetFolder() As String
Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
NextCode:
    GetFolder = sItem
    Set fldr = Nothing
End Function

Sub CBFolder_Click()
Application.EnableEvents = False
Application.EnableEvents = True
Dim LsR As Long
    LsR = Cells(Rows.Count, "B").End(xlUp).Row
Dim dcell As Range
Dim MainstrFolders As String
        MainstrFolders = GetFolder
    Dim strFolders As String
    For Each dcell In Range(Cells(3, 8), Cells(LsR, 8))
            strFolders = MainstrFolders & "\" & dcell.Offset(0, -6) & "\" & dcell.Offset(0, -5) & "\" & dcell.Offset(0, -4) & "\" & dcell.Offset(0, -3) & "\" & dcell.Offset(0, -2) & "\" & dcell.Offset(0, -1) & "\" & dcell.Value
        Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))
    Next
End Sub
 

Attachments

  • Make Dirs.jpg
    Make Dirs.jpg
    76.7 KB · Views: 7
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top