File Management - MKDir
(i)Create new Folder:
Private Sub CommandButton1_Click()
MkDir ("C:\CreateFolder")
End Sub
(ii)Create Sub Folders in a Folder:
Private Sub CommandButton1_Click()
MkDir ("C:\CreateFolder\Apple")
MkDir ("C:\CreateFolder\Sriguranjani")
MkDir ("C:\CreateFolder\Banana")
MkDir ("C:\CreateFolder\Orange")
MkDir ("C:\CreateFolder\Pen")
End Sub
(iii)Create Sub Folders in a Folder from pre-determined range
Private Sub CommandButton1_Click()
MkDir ("C:\ABC")
Dim source As String, filename As String
source = "c:\abc\"
Dim max As Integer
Max = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
For i = 1 To Max
filename = Cells(i, 1).Value
MkDir (source & filename)
Next
End Sub
First create directory\folder with the name of ABC
Define variables as SOURCE & FILENAME to store the Folder and Subfolder names in looping process
Assign source path to variable
Define variable to store SUBFOLDERS data
Assign values to FOR LOOP
Assign value to FILENAME variable
Create sub folders
(iv)Create Folder & Sub folder in different drives:
Private Sub CommandButton1_Click()
Dim dri As Integer
dri = Range(Range("C15"), Range("C15").End(xlToRight)).Columns.Count
c = 3
For i = 1 To dri
drname = Cells(15, c)
MsgBox drname & ":\" & Range("D4").Value & "\"
drive = drname & ":\" & Range("D4").Value & "\"
'MkDir (drname & ":\" & "abc")
MkDir (drive)
Dim subfolder As String
Dim max As Integer
max = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
For h = 1 To max
subfolder = Cells(h, 1).Value
'MsgBox drive & filename
MkDir (drive & subfolder)
Next
c = c + 1
Next
End Sub
Result: Folder and subfolders created in 3 drives C,D,E: