1、启用宏功能
2、新建Excel文档,设置宏
3、运行
-------------------------------------------------------------------------------------------------------------------------
1、文件》选项》信任中心》信任中心设置》宏设置》启用所有宏》确定
2、新建Excel文档》选中视图》录制宏》确定》查看宏》编辑》复制下方全部代码》点击执行
代码:说明(其中fPath是原始csv文件的地址,sPath是转出的xlsx文件地址,最后的\不要掉了)
Sub CAVToXLSX()
Dim fDir As String
Dim wB As Workbook
Dim wS As Worksheet
Dim fPath As String
Dim sPath As String
fPath = "原始csv文件的地址\"
sPath = "转出的xlsx文件地址\"
fDir = Dir(fPath)
Do While (fDir <> "")
If Right(fDir, 4) = ".csv" Or Right(fDir, 5) = ".csv" Then
On Error Resume Next
Set wB = Workbooks.Open(fPath & fDir)
'MsgBox (wB.Name)
For Each wS In wB.Sheets
wS.SaveAs sPath & wB.Name & ".xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Next wS
wB.Close False
Set wB = Nothing
End If
fDir = Dir
On Error GoTo 0
Loop
End Sub
3、运行