How to batch convert multiple Excel files to CSV files in Excel?
In Excel, we can convert the workbook to CSV file with the Save as function, but could you know how to batch convert multiple Excel files to separate CSV files? In this article, I introduce a VBA code to batch convert all Excel files in a folder to CSV files in Excel.
Batch convert Excel files of a folder to CSV files with VBA
Convert sheets of workbook into separate CSV files with Kutools for Excel
Batch convert Excel files of a folder to CSV files with VBA
In Excel, there is no built-in function can solve this job quickly except VBA.
1. Enable Excel, and press Alt + F11 keys open Microsoft Visual Basic for Applications window.
2. Click Insert > Module to create a new Module.
3. Copy below code and paste them to the new Module window.
VBA: Batch convert Excel files to CSV
Sub WorkbooksSaveAsCsvToFolder()
'UpdatebyExtendoffice20181031
Dim xObjWB As Workbook
Dim xObjWS As Worksheet
Dim xStrEFPath As String
Dim xStrEFFile As String
Dim xObjFD As FileDialog
Dim xObjSFD As FileDialog
Dim xStrSPath As String
Dim xStrCSVFName As String
Dim xS As String
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
On Error Resume Next
Set xObjFD = Application.FileDialog(msoFileDialogFolderPicker)
xObjFD.AllowMultiSelect = False
xObjFD.Title = "Kutools for Excel - Select a folder which contains Excel files"
If xObjFD.Show <> -1 Then Exit Sub
xStrEFPath = xObjFD.SelectedItems(1) & "\"
Set xObjSFD = Application.FileDialog(msoFileDialogFolderPicker)
xObjSFD.AllowMultiSelect = False
xObjSFD.Title = "Kutools for Excel - Select a folder to locate CSV files"
If xObjSFD.Show <> -1 Then Exit Sub
xStrSPath = xObjSFD.SelectedItems(1) & "\"
xStrEFFile = Dir(xStrEFPath & "*.xls*")
Do While xStrEFFile <> ""
xS = xStrEFPath & xStrEFFile
Set xObjWB = Application.Workbooks.Open(xS)
xStrCSVFName = xStrSPath & Left(xStrEFFile, InStr(1, xStrEFFile, ".") - 1) & ".csv"
xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=xlCSV
xObjWB.Close savechanges:=False
xStrEFFile = Dir
Loop
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
4. Press F5 key, select the folder contains the Excel files you want to convert to CSV files in first popping dialog.
5. Click OK, then in the second popping dialog, select the folder to place the CSV files.
6. Click OK, now the Excel files in the folder have been converted to CSV files and saved in another folder.
Convert sheets of workbook into separate CSV files with Kutools for Excel
As we known, we only can convert the whole workbook into one CSV file in Excel with its Save As function. But in some times, you want to convert the single sheet into CSV file, in this case, the Split Workbook utility of Kutools for Excel can help you.
After installing Kutools for Excel, please do as below:(Free Download Kutools for Excel Now!)
1. Enable workbook you want to convert its sheets as separate CSV files, click Kutools Plus > Workbook > Split Workbook.
2. In the Split Workbook dialog, check the sheet name you want to split (all sheets are checked by default), check Save as type, choose CSV (Macintosh) (*.CSV) from the drop-down list.
3. Click Split to pop out a Browse For Folder dialog, choose or create a folder to place the CSV files.
4. Click OK, now the workbook has been split as separate CSV files.
Split Workbook
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!