Sub SaveToExcel()Dim fDir AsStringDim wB As Workbook
Dim wS As Worksheet
Dim fPath AsStringDim sPath AsStringDim csvFilePath AsStringDim excelFilePath AsString
fPath ="d:\user\01426442\桌面\新建文件夹\csv\"
sPath ="d:\user\01426442\桌面\新建文件夹\excel\"
fDir = Dir(fPath)DoWhile(fDir <>"")IfRight(fDir,4)=".csv"Then
csvFilePath = fPath & fDir
excelFilePath = sPath & Replace(fDir,".csv","")&".xlsx"' Import CSV data into a new Excel workbookWith Workbooks.Open(csvFilePath)
.Sheets(1).Copy
EndWith' Save the new workbook as Excel file
ActiveWorkbook.SaveAs excelFilePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=FalseEndIf
fDir = Dir
LoopEndSub