Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in


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 Excelgood idea3

Tabbed browsing & editing multiple Excel workbooks/Word documents as Firefox, Chrome, Internet Explore 10!

You may be familiar to view multiple webpages in Firefox/Chrome/IE, and switch between them by clicking corresponding tabs easily. Here, Office Tab supports similar processing, which allow you to browse multiple Excel workbooks or Word documents in one Excel window or Word window, and easily switch between them by clicking their tabs. Click for free 45-day trial of Office Tab!

ot 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()
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

    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
    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 <> ""
        Set xObjWB = Workbooks.Open(Filename:=xStrEFPath & xStrEFFile)
        xStrCSVFName = xStrSPath & Left(xStrEFFile, InStr(1, xStrEFFile, ".") - 1) & ".csv"
        xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=xlCSV
        xObjWB.Close savechanges:=False
        xStrEFFile = Dir
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = 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.
doc batch to csv 1

5. Click OK, then in the second popping dialog, select the folder to place the CSV files.
doc batch to csv 2

6. Click OK, now the Excel files in the folder have been converted to CSV files and saved in another folder.
doc batch to csv 3

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.

Kutools for Excel, with more than 200 handy functions, makes your jobs easier. 

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.
doc batch to csv 4

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.
doc batch to csv 5

3. Click Split to pop out a Browse For Folder dialog, choose or create a folder to place the CSV files.
doc batch to csv 6

4. Click OK, now the workbook has been split as separate CSV files.
doc batch to csv 7

Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Sam · 1 months ago
    Another small remark:

    If the cells in the original Excel files are all formatted as "General", some accuracy is lost when the file is saved as a CSV
    For example, if a cell value in Excel is 0.123456789123456, then the value in the CSV will be 0.123456789 (missing the remaining decimals), as long as the cell was formatted as 'General'. This can be solved by formatting all cells in the Excel file to anything else than 'General' (for example, 'Text'). In that case, the CSV *will* still have the full detail/accuracy. I.e. the values in the Excel files will be fully intact after saving as a CSV.

    How could this macro be changes, so it sets the formatting of all cells in the Excel file to 'Text', before saving as a CSV?
    I imagine that it must somehow make use of the following, but I can't figure out how to correctly include in within the macro:

    Selection.NumberFormat = "@"
  • To post as a guest, your comment is unpublished.
    Sam · 2 months ago
    Works great, thanks for the code!
    My only remark would be that this code cuts of file names when there is a "." in the filename itself (e.g. file.123.csv turns into file.csv).
  • To post as a guest, your comment is unpublished.
    Aman · 6 months ago
    Ty it really works dear !!