1、新建一个excel
2、选择alt+F11
3、选择insert model
4、输入程序,选择包含csv文件的文件夹
1 Sub CSVtoXLS() 2 'UpdatebyExtendoffice20170814 3 Dim xFd As FileDialog 4 Dim xSPath As String 5 Dim xCSVFile As String 6 Dim xWsheet As String 7 Application.DisplayAlerts = False 8 Application.StatusBar = True 9 xWsheet = ActiveWorkbook.Name 10 Set xFd = Application.FileDialog(msoFileDialogFolderPicker) 11 xFd.Title = "Select a folder:" 12 If xFd.Show = -1 Then 13 xSPath = xFd.SelectedItems(1) 14 Else 15 Exit Sub 16 End If 17 If Right(xSPath, 1) <> "" Then xSPath = xSPath + "" 18 xCSVFile = Dir(xSPath & "*.csv") 19 Do While xCSVFile <> "" 20 Application.StatusBar = "Converting: " & xCSVFile 21 Workbooks.Open Filename:=xSPath & xCSVFile 22 ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xls", vbTextCompare), xlNormal 23 ActiveWorkbook.Close 24 Windows(xWsheet).Activate 25 xCSVFile = Dir 26 Loop 27 Application.StatusBar = False 28 Application.DisplayAlerts = True 29 End Sub