How to batch convert multiple CSV files to XLS(X) files in Excel?
To convert a CSV file to XlS or XLSX file is very easy for you by applying the Save As feature. However, to convert multiple CSV files to XLS or XLSX files from a folder is time-consuming by saving one by one manually. Here I introduce a macro code to quickly batch convert all CSV files to XLS(x) files from a folder.
Batch convert CSV files to XlS(X) files with macro code
Batch convert CSV files to XlS(X) files with macro code
To convert multiple CSV files from one folder to XLS(X) files, you can do as below steps:
1. Enable a new workbook, press Alt + F11 keys to open Microsoft Visual Basic for Applications window, and click Insert > Module. See screenshot:
Note: Make sure all CSV files you want to convert are closed.
2. Then paste below macro code to the Module script, and press F5 key to run the code.
VBA: Convert CSV to XLS
Sub CSVtoXLS()
'UpdatebyExtendoffice20170814
Dim xFd As FileDialog
Dim xSPath As String
Dim xCSVFile As String
Dim xWsheet As String
Application.DisplayAlerts = False
Application.StatusBar = True
xWsheet = ActiveWorkbook.Name
Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
xFd.Title = "Select a folder:"
If xFd.Show = -1 Then
xSPath = xFd.SelectedItems(1)
Else
Exit Sub
End If
If Right(xSPath, 1) <> "\" Then xSPath = xSPath + "\"
xCSVFile = Dir(xSPath & "*.csv")
Do While xCSVFile <> ""
Application.StatusBar = "Converting: " & xCSVFile
Workbooks.Open Filename:=xSPath & xCSVFile
ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xls", vbTextCompare), xlNormal
ActiveWorkbook.Close
Windows(xWsheet).Activate
xCSVFile = Dir
Loop
Application.StatusBar = False
Application.DisplayAlerts = True
End Sub
3. In the popping out dialog, select the specified folder containing the CSV files you want to convert. See screenshot:
4. Click OK, all the CSV files in the selected folder have been converted to XLS files in it.
Tip: If you want to convert CSV files to XLSX files, you use below VBA code.
VBA: Convert CSV files to XLSX
Sub CSVtoXLS()
'UpdatebyExtendoffice20170814
Dim xFd As FileDialog
Dim xSPath As String
Dim xCSVFile As String
Dim xWsheet As String
Application.DisplayAlerts = False
Application.StatusBar = True
xWsheet = ActiveWorkbook.Name
Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
xFd.Title = "Select a folder:"
If xFd.Show = -1 Then
xSPath = xFd.SelectedItems(1)
Else
Exit Sub
End If
If Right(xSPath, 1) <> "\" Then xSPath = xSPath + "\"
xCSVFile = Dir(xSPath & "*.csv")
Do While xCSVFile <> ""
Application.StatusBar = "Converting: " & xCSVFile
Workbooks.Open Filename:=xSPath & xCSVFile
ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xlsx", vbTextCompare), xlWorkbookDefault
ActiveWorkbook.Close
Windows(xWsheet).Activate
xCSVFile = Dir
Loop
Application.StatusBar = False
Application.DisplayAlerts = True
End Sub
quickly convert or export a range of a sheet to separate XLS/Word/PDF or other format files in once time
|
Normally, Excel does not support you with an option to quickly export or save a range as a CSV or Excel file. If you want to save a range of data as a CSV or workbook in Excel, you may need to use a VBA Macro for doing this or to copy the range to clipboard and paste it in a new workbook and then save the workbook as CSV or Workbook. Kutools for Excel augments Excel with Export Range to File utility for Excel users who want to quickly process the following operations: Click for 30-day full featured free trial! |
![]() |
Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. |
Relative Articles:
- How to convert csv file to xls file or import/open csv in Excel?
- How to convert word document to excel worksheet?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
















