根据excel文本,一一对应生成新建文件夹,代码如下:
Sub CreateFoldersFromList()
Dim ws As Worksheet
Dim folderPath As String
Dim cell As Range
Dim folderName As String
Dim folderPathComplete As String
' 设置工作表,这里假设是活动工作表
Set ws = ActiveSheet
' 设置目标文件夹路径
' 请将此路径替换为你的目标文件夹路径
folderPath = "C:\Users\Administrator\Desktop\2025\"
' 确保路径以反斜杠结尾
If Right(folderPath, 1) <> "\" Then
folderPath = folderPath & "\"
End If
' 遍历第一列的每一个单元格
For Each cell In ws.Range("A1:A" & ws.Cells(ws.Rows.Count, 1).End(xlUp).Row)
folderName = cell.Value
folderPathComplete = folderPath & folderName
' 检查文件夹是否存在,如果不存在则创建
If Dir(folderPathComplete, vbDirectory) = "" Then
MkDir folderPathComplete
Debug.Print "Created folder: " & folderName
Else
Debug.Print "Folder already exists: " & folderName
End If
Next cell
MsgBox "Folders have been created based on the list in column A."
End Sub