vba: csv文件批量转换为xlsx的宏
作者:互联网
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", ".xlsx", 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
标签:Dim,vba,csv,xFd,Application,xSPath,xCSVFile,文件批量 来源: https://www.cnblogs.com/yukit/p/13605770.html