其他分享
首页 > 其他分享> > xlsx文件批量转格式(txt、csv) (转载)

xlsx文件批量转格式(txt、csv) (转载)

作者:互联网

 

转载:https://zhuanlan.zhihu.com/p/33301784

 

 

'处理成txt类型
Sub getTXT()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim i%, file As Variant, path$
Dim data As Workbook
'这里用GetOpenFilename弹出一个多选窗口,选中我们要转化成csv的xlsx文件,
file = Application.GetOpenFilename(MultiSelect:=True)
'用LBound和UBound
For i = LBound(file) To UBound(file)
    Workbooks.Open Filename:=file(i)
    Set data = ActiveWorkbook
    path = data.path
    '这里设置要保存在目录下面的csv文件夹里,之后可以自己调
    '参考了里面的第一种方法
    On Error Resume Next
    VBA.MkDir (path & "\txt")
    With data
        .SaveAs path & "\txt\" & Replace(data.Name, ".xlsx", ".txt"), xlUnicodeText
        .Close True
      End With
Next i
'弹出对话框表示转化已完成,这时去相应地方的csv里查看即可
MsgBox "已转换了" & (i - 1) & "个文档"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

 

 

标签:xlsx,文件批量,True,Application,file,path,txt,data
来源: https://www.cnblogs.com/redufa/p/13685903.html