批量创建文件夹和文件——excel VBA实现

当需要创建大量文件夹及文件时,可借助excel vba 实现,如下图:

批量创建文件名为1-10的文件夹,每个文件夹内有个与文件名相同的txt文件,txt文件内的数字也跟文件名相同。

附代码:

vbnet 复制代码
Sub CreateFoldersAndFiles()


    Dim i As Integer
    Dim folderPath As String
    Dim filePath As String
    Dim textFile As Integer
    
    ' 获取当前Excel文件所在的文件夹路径
    folderPath = ThisWorkbook.Path & "\"
    
    ' 循环创建10个文件夹和txt文件
    For i = 1 To 10
        ' 创建文件夹
        MkDir folderPath & i
        
        ' 生成txt文件路径
        filePath = folderPath & i & "\" & i & ".txt"
        
        ' 创建并写入txt文件
        textFile = FreeFile
        Open filePath For Output As textFile
        Print #textFile, i
        Close textFile
    Next i
    
    MsgBox "文件夹和文件创建完成!" 
End Sub

代码代写,可点击下方联系 ↓

相关推荐
夜流冰24 分钟前
Excel - MS Support for Excel: 2 Collaborate
数据库·windows·excel
LingRannn8 小时前
【vim 中如何替换】
编辑器·vim·excel
yesyesido9 小时前
智能文件格式转换器:文本/Excel与CSV无缝互转的在线工具
开发语言·python·excel
开开心心_Every1 天前
免费进销存管理软件:云端本地双部署
java·游戏·微信·eclipse·pdf·excel·语音识别
Kasen's experience1 天前
Excel 怎么快速合并同一个ID不同行的大量相同单元格
excel
mudtools1 天前
基于.NET操作Excel COM组件生成数据透视报表
c#·.net·excel
yangminlei1 天前
Spring Boot+EasyExcel 实战:大数据量 Excel 导出(高效无 OOM)
spring boot·后端·excel
NignSah1 天前
Microsoft Excel World Championship 2025-2025EXCEL大赛,折纸
microsoft·excel
hhzz1 天前
Springboot项目中使用POI操作Excel(详细教程系列1/3)
spring boot·后端·excel·poi·easypoi
林月明1 天前
【VBA】点击一个按钮实现自动更新excel文件列数据
excel·vba·宏文件·一键数据更新