excel 批量格式转换
Posted 旧客图新
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了excel 批量格式转换相关的知识,希望对你有一定的参考价值。
脚本运行方式
在需要转换的csv或者xls同目录新建一个xls文件,alt+f11打开VBA project,然后将代码贴入,点击运行即可。
XLS批量转换为CSV
Sub xls2csv() Application.DisplayAlerts = False t = ActiveWorkbook.Name mypath = ActiveWorkbook.Path & "\" myfile = Dir(mypath & "*.xls") Do Until Len(myfile) = 0 If myfile <> t Then Workbooks.Open Filename:=mypath & myfile ActiveWorkbook.SaveAs Filename:=mypath & Left(myfile, InStr(myfile, ".") - 1) & ".csv", FileFormat:=xlCSV End If If myfile <> t Then ActiveWorkbook.Close myfile = Dir Loop Application.DisplayAlerts = True End Sub
CSV批量转XLS
Sub xls2csv() Application.DisplayAlerts = False t = ActiveWorkbook.Name mypath = ActiveWorkbook.Path & "\" myfile = Dir(mypath & "*.csv") Do Until Len(myfile) = 0 If myfile <> t Then Workbooks.Open Filename:=mypath & myfile ActiveWorkbook.SaveAs Filename:=mypath & Left(myfile, InStr(myfile, ".") - 1) & ".xls", FileFormat:=xlExcel8 End If If myfile <> t Then ActiveWorkbook.Close myfile = Dir Loop Application.DisplayAlerts = True End Sub
如有疑问,请留言。
以上是关于excel 批量格式转换的主要内容,如果未能解决你的问题,请参考以下文章
使用VBA批量转换Excel格式,由.xls转换成.xlsx