Top macro works, bottom one doesn't unless I run the top one first. How do I create folder & subfolder concurrently?
I'm trying to use FileSystemObject.CreateFolder to make a folder and subfolder at the same time. The top macro works and the bottom one dosen't. The bottom macro will successfully run if I run the top one first.
Go ahead guys, make me look like an idiot.
Sub MakeDir1() ' this macro works
Dim DocPath As String
DocPath = "E:\@Workorders\test\" ' E:\@Workorders\ is an existing folder
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
If Not FSO.FolderExists(DocPath) Then
FSO.CreateFolder (DocPath)
End If
End Sub
Sub MakeDir2() ' this macro throws an error at "FSO.CreateFolder (DocPath)"
Dim DocPath As String
DocPath = "E:\@Workorders\test\test2\"
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
If Not FSO.FolderExists(DocPath) Then
FSO.CreateFolder (DocPath)
End If
End Sub
This works: