在excel中创建并运行宏命令:(红色部分根据需要进行修改)
Sub CSVTOXLSX()
Dim fDir As String
Dim wB As Workbook
Dim wS As Worksheet
Dim fPath As String
Dim sPath As String
fPath = "D:\……"
sPath = "D:\……"
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