Private Sub Form_Load()
SubDirectories
End
End Sub
Private Sub SubDirectories()
Dim fsO As Object
Dim oDirectory As Object
Dim oFolders As Object
Dim oSubDir As Object
' Check if the directory already exists
If Dir$("A:\MyDirectory", vbDirectory) <> "" Then
MsgBox ("The directory 'MyDirectory' exists already; delete it or change disks!")
Else
Set fsO = CreateObject("Scripting.filesystemObject")
' Create the directory
Set oDirectory = fsO.CreateFolder("A:\MyDirectory")
' Establish it as a container of folder objects
Set oFolders = oDirectory.SubFolders
' Add a sub directory to MyDirectory without mentionning it's location!
Set oSubDir = oFolders.Add("SubDirectory")
End If
Set fsO = Nothing
Set oDirectory = Nothing
Set oFolders = Nothing
Set oSubDir = Nothing
End Sub