Sub MyCreateFolders()
Dim pickFolder As FileDialog
Dim myPath As String
Dim yr As Long
Dim m As Long
Dim fl As String
' Select path/folder from dialog box
Set pickFolder = Application.FileDialog(msoFileDialogFolderPicker)
With pickFolder
.Title = "Select A Folder"
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub 'Check to see if cancel button clicked
myPath = .SelectedItems(1) & "\"
End With
' Prompt user for year to create
On Error GoTo err_fix
yr = InputBox("Please enter the year you would like to create folders for")
On Error GoTo 0
' Loop through all months for the year
For m = 1 To 12
' Build new folder name
fl = Format(DateSerial(yr, m, 1), "mm mmm yyyy")
' Create folder
MkDir (myPath & fl)
Next m
MsgBox "Macro complete!"
Exit Sub
err_fix:
MsgBox "Invalid folder name", vbOKOnly, "Process Aborted!"
End Sub