根据表格的文件名称批量新建文件夹

编程入门 行业动态 更新时间:2024-10-23 04:58:26

根据表格的<a href=https://www.elefans.com/category/jswz/34/1735003.html style=文件名称批量新建文件夹"/>

根据表格的文件名称批量新建文件夹

标题程序要求

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

更多推荐

根据表格的文件名称批量新建文件夹

本文发布于:2024-02-07 00:26:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1751914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名称   批量   文件夹   表格

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!