我正在尝试创建一个以 Excel 工作表作为源的 5 级文件夹。
注意:Excel 工作表是按每列上的级别组织的列,如图所示。
参考 VB 脚本:
https://superuser.com/questions/799666/creating-folders-and-sub-folders-with-a-vba-macro
错误:
**'Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))**
脚本:
Sub CreateFolderStructure()
Dim objRow As Range, objCell As Range, strFolders As String
For Each objRow In ActiveSheet.UsedRange.Rows
strFolders = "C:\Users\morar\Downloads\FoldersNSubsr"
For Each objCell In objRow.Cells
strFolders = strFolders & "\" & objCell
Next
**Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))**
Next
End Sub
我还没找到解决办法。
无壳:
Sub CreateFolderStructure()
Const ROOT_DIR As String = "C:\Temp"
Dim objRow As Range, c As Range, strFolders As String, v
For Each objRow In ActiveSheet.UsedRange.Rows
strFolders = ROOT_DIR
For Each c In objRow.Cells
v = Trim(c.Value)
If Len(v) > 0 Then
strFolders = strFolders & "\" & v
'do we need to create this folder?
If Dir(strFolders, vbDirectory) = vbNullString Then
Debug.Print "Creating: " & strFolders
MkDir strFolders
Else
Debug.Print "Exists: " & strFolders
End If
End If
Next c
Next objRow
End Sub