文件名称批量新建文件夹"/>
根据表格的文件名称批量新建文件夹
标题程序要求
Excel表格中,A列信息为批量新建文件夹的信息,其中A1为标题,其他为新建文件夹的名称,根据文件夹的名称在指定的路径下新建文件夹
操作步骤
2.1. 确定新建文件夹的名称
2.2. 打开代码编译器
按住alt+F11打开代码编译器,或者对着表格名称鼠标右键选择查看代码
2.3. 新建类模块
在编译器中选择插入类模块,新建模块
2.4. 添加代码
将第三节可实现的代码复制到编辑框
2.5. 运行
选择F5完成运行,或者在编译器运行中选择运行
2.6. 选择指定的文件并完成运行
标题可实现的代码
Sub CreateFolders()
Dim cell As Range
Dim folderPath As String
Dim parentFolder As Variant
'Prompt the user to select a folder using the FolderDialog method
Set parentFolder = Application.FileDialog(msoFileDialogFolderPicker)
With parentFolder.Title = "Select a folder".AllowMultiSelect = FalseIf .Show <> -1 Then Exit Sub 'User cancelledparentFolder = .SelectedItems(1)
End With'Loop through each cell in column A, starting from row 2
For Each cell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)'Check if the cell is not emptyIf Not IsEmpty(cell.Value) Then'Construct the folder pathfolderPath = parentFolder & "\" & cell.Value'Check if the folder already existsIf Dir(folderPath, vbDirectory) = "" Then'Create the folder if it doesn't existMkDir folderPathEnd IfEnd If
Next cell'Display a message when the process is complete
MsgBox "Folders have been created in the selected folder based on the values in column A."
End Sub
更多推荐
根据表格的文件名称批量新建文件夹
发布评论