【一步一步学习VBA】将Excel的每行数据导出为txt文本

    xiaoxiao2025-03-12  13

    这里我就直接上源码:

    Sub 导出每行为txt() Dim i, j, arr(), brr(), myRow, myCol arr = Sheet1.UsedRange '将工作表的内容放入arr数组中 myRow = UBound(arr, 1) '计算出数组的行数 myCol = UBound(arr, 2) '计算出数组的列数 For i = 1 To myRow '从第2行开始循环 Open ThisWorkbook.Path & "\" & arr(i, 1) & "1.txt" For Output As #1 '打开一个以第一列数据命名的txt Print #1, Join(Application.Index(arr, 1), ",") '输出表头 Print #1, Join(Application.Index(arr, i), ",") '输出内容 Close #1 '关闭 Next '循环 End Sub 参考文章: 点击

    转载请注明原文地址: https://ju.6miu.com/read-1296974.html
    最新回复(0)