vba:csv文件批量轉換為xls的宏


 
         

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM