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

标题程序要求

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 = False
    If .Show <> -1 Then Exit Sub 'User cancelled
    parentFolder = .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 empty
    If Not IsEmpty(cell.Value) Then
        'Construct the folder path
        folderPath = parentFolder & "\" & cell.Value
        
        'Check if the folder already exists
        If Dir(folderPath, vbDirectory) = "" Then
            'Create the folder if it doesn't exist
            MkDir folderPath
        End If
    End 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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

没有小数点

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值