Skip to content

Instantly share code, notes, and snippets.

@xxdoc
Created July 20, 2018 04:27
Show Gist options
  • Select an option

  • Save xxdoc/7a75fbf26121b4bdada2530c40fdc95a to your computer and use it in GitHub Desktop.

Select an option

Save xxdoc/7a75fbf26121b4bdada2530c40fdc95a to your computer and use it in GitHub Desktop.
' Source: VBA – Create Directory Structure/Create Multiple Directories/Create Nested Directories
' URL: https://www.devhut.net/2011/09/15/vba-create-directory-structurecreate-multiple-directories/
' Daniel Pineault, 15SEP2011.
Public Sub CreateDir(sPath As String)
' Source: https://www.devhut.net/2011/09/15/vba-create-directory-structurecreate-multiple-directories/
Dim iStart As Integer
Dim aDirs As Variant
Dim sCurDir As String
Dim i As Integer
If sPath <> "" Then
aDirs = Split(sPath, "\")
If Left(sPath, 2) = "\\" Then
iStart = 3
Else
iStart = 1
End If
sCurDir = Left(sPath, InStr(iStart, sPath, "\"))
For i = iStart To UBound(aDirs)
sCurDir = sCurDir & aDirs(i) & "\"
If Dir(sCurDir, vbDirectory) = vbNullString Then
MkDir sCurDir
End If
Next i
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment