顶部宏有效,底部宏不起作用,除非我先运行顶部宏。如何同时创建文件夹和子文件夹?
我正在尝试同时FileSystemObject.CreateFolder创建一个文件夹和子文件夹。顶部宏有效,底部宏无效。如果我先运行顶部宏,底部宏将成功运行。
来吧,伙计们,让我看起来像个白痴。
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