作者:森眺
链接:https://www.zhihu.com/question/39234324/answer/284625834
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
Sub CAVToXLSX()
Dim fDir As String
Dim wB As Workbook
Dim wS As Worksheet
Dim fPath As String
Dim sPath As String
fPath = "C:\Users\Micro\Desktop\source\"
sPath = "C:\Users\Micro\Desktop\target\"
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