Created
July 20, 2018 04:27
-
-
Save xxdoc/7a75fbf26121b4bdada2530c40fdc95a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' 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