# Create Folders and Sub Folders



## shyoung192 (Dec 27, 2022)

I used this VBA code to create 2022 folders flawlessly, now when trying to create 2023 folders I am getting an error message...
Runtime Error '5'
Invalid Procedure call or Argument
Debug is on the "Shell ("cmd/c md"&... )) Line
It is asking me to put in a Folder name and I can't remember the format I used... 
Any assistance would be greatly appreciated...

Sub FolderCreator()

    Dim objRow As Range, objCell As Range, strFolders As String, rootFolder As String

    With Application.FileDialog(msoFileDialogFolderPicker)
        ' show the file picker dialog box
        If .Show <> 0 Then
            rootFolder = .SelectedItems(1)
              End If
    End With

    For Each objRow In ActiveSheet.UsedRange.Rows
        strFolders = rootFolder
        For Each objCell In objRow.Cells
            strFolders = strFolders & "\" & objCell
        Next
        Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))
    Next

End Sub


----------



## rollis13 (Dec 27, 2022)

Your macro is still in working conditions. All you need is a list of (new) folder names in an active sheet (no other data in this sheet). Then launch the macro and it will ask for the root folder.


----------



## shyoung192 (Dec 27, 2022)

rollis13 said:


> Your macro is still in working conditions. All you need is a list of (new) folder names in an active sheet (no other data in this sheet). Then launch the macro and it will ask for the root folder.


Thank you for checking.  So, when it ask me for the FOLDER name, do I put the full path, i.e. C:\Users\Desktop\Payroll Testing\2023 or (?) because it is not working for me and I know I am doing something wrong?


----------



## rollis13 (Dec 27, 2022)

No, not necessary, the full path will be detected by the macro when it asks you to browse to the root folder.
As per your example: since you already have a folder named Payroll Testing on your desktop (your root folder),  write 2023 in cell A1 of an empty sheet and launch your macro from there. If you have to create other subfolders in your new 2023 folder just delete cell A1, write down, starting from A1, all the names of new folders to be created, launch your macro and now browse to the newly create folder 2023. That's all.


----------



## shyoung192 (Dec 27, 2022)

rollis13 said:


> No, not necessary, the full path will be detected by the macro when it asks you to browse to the root folder.
> As per your example: since you already have a folder named Payroll Testing on your desktop (your root folder),  write 2023 in cell A1 of an empty sheet and launch your macro from there. If you have to create other subfolders in your new 2023 folder just delete cell A1, write down, starting from A1, all the names of new folders to be created, launch your macro and now browse to the newly create folder 2023. That's all.


rollis13...YOU'RE THE BEST...Thank you and I APPRECIATE your assistance!!!


----------



## rollis13 (Dec 27, 2022)

To create any folder and subfolders at once you can write:
2023\test1
or even:
2023\test1\test2

Thanks for the positive feedback, glad having been of some help.


----------

