In modern data pipelines and analytics architectures, legacy Excel formats like .xls and modern .xlsx workbooks often present significant obstacles. While Excel is ideal for human manipulation, machine learning algorithms, database ingestion pipelines, and ETL systems require simpler formats. If you need to convert multiple xls to csv files, performing this manually is a massive bottleneck.
Whether you have ten files or ten thousand, this comprehensive guide covers the best, most reliable methods to batch convert your spreadsheets. We will explore how to automate this process using Excel VBA macros, robust Python scripts, Windows PowerShell, and native Excel features. Additionally, we will cover the reverse workflow—how to combine multiple csv to excel sheets—and address major pitfalls like character encoding and formatting losses.
1. Why Convert XLS/XLSX to CSV? Understanding the Core Formats
Before executing bulk actions, it is helpful to understand the architectural differences between a spreadsheet workbook and a flat file. An Excel file (.xls or .xlsx) is essentially a compressed XML container. It holds metadata, presentation formatting, visual styles, custom fonts, charts, formulas, and most importantly, it can house multiple individual worksheets.
Conversely, a Comma-Separated Values (.csv) file is a pure, unformatted text file. It uses a character delimiter (typically a comma) to separate fields and newlines to separate records.
Because CSV is lightweight and universal, database engines (like PostgreSQL, MySQL, and Snowflake) and cloud storage architectures prefer it. However, converting to CSV presents a unique technical hurdle: CSV files can only store a single active sheet.
When you attempt to convert excel with multiple sheets to csv, you cannot simply "save as" a single CSV. If you do, Excel will save only the currently active worksheet and quietly discard the rest. Therefore, any true batch-processing system must be smart enough to open each workbook, iterate through every sheet, and export them as individual, clearly named CSV files.
2. The Excel Macro Solution: Batch Convert Using VBA
If you want a code-free environment but still need to convert hundreds of files, utilizing Excel's built-in Visual Basic for Applications (VBA) engine is your best option. Writing a macro allows you to convert all excel files in folder to csv without installing any third-party dependencies.
Step-by-Step Guide to Setting Up the VBA Macro
- Open a blank Excel workbook.
- Press
Alt + F11to open the VBA Editor interface. - Click Insert from the top menu and select Module.
- Copy and paste the robust VBA code below into the module window.
- Press
F5or click the green Run button to execute the program.
Sub BatchConvertXlsToCsv()
Dim xFolder As FileDialog
Dim xInputPath As String
Dim xOutputPath As String
Dim xFile As String
Dim wb As Workbook
Dim ws As Worksheet
Dim saveName As String
' Step 1: Select Folder containing the target Excel files
Set xFolder = Application.FileDialog(msoFileDialogFolderPicker)
xFolder.Title = "Select the Folder Containing Your Excel Files"
If xFolder.Show = -1 Then
xInputPath = xFolder.SelectedItems(1) & "\"
Else
Exit Sub
End If
' Step 2: Select the Output Folder for CSVs
xFolder.Title = "Select the Destination Folder for CSV Outputs"
If xFolder.Show = -1 Then
xOutputPath = xFolder.SelectedItems(1) & "\"
Else
Exit Sub
End If
' Optimize execution speed by disabling alerts and updates
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' Look for both legacy (.xls) and modern (.xlsx) extensions
xFile = Dir(xInputPath & "*.xl*")
Do While xFile <> ""
' Open the target workbook in read-only mode without updating links
Set wb = Workbooks.Open(xInputPath & xFile, UpdateLinks:=False, ReadOnly:=True)
' Convert multiple excel sheets to csv format individually
For Each ws In wb.Worksheets
' Ensure we only export worksheets containing data
If Application.WorksheetFunction.CountA(ws.Cells) > 0 Then
' Clean the original file name
saveName = Left(xFile, InStrRev(xFile, ".") - 1)
' If there are multiple sheets, append sheet name to avoid overwriting
If wb.Worksheets.Count > 1 Then
saveName = saveName & "_" & ws.Name
End If
' Copy worksheet to a temporary workbook and save as CSV
ws.Copy
ActiveWorkbook.SaveAs Filename:=xOutputPath & saveName & ".csv", _
FileFormat:=xlCSVUTF8
ActiveWorkbook.Close SaveChanges:=False
End If
Next ws
wb.Close SaveChanges:=False
xFile = Dir()
Loop
' Re-enable application settings
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "Batch conversion successfully complete!", vbInformation, "Success"
End Sub
How This VBA Code Works
This macro uses directory scanning to find any files with extensions starting with .xl. It addresses the multi-sheet data loss risk by checking the sheet count of each workbook. If multiple sheets exist, it saves each sheet as a separate file with the naming convention OriginalWorkbookName_SheetName.csv. Saving with xlCSVUTF8 ensures special, non-English characters are preserved using UTF-8 formatting.
3. The Developer's Choice: Convert Multiple Excel Files to CSV in Python
For programmers, data scientists, and engineers, to convert multiple excel files to csv python is the undisputed champion. Python provides incredible speed, allows you to integrate the code directly into broader automated pipelines, and does not require Microsoft Excel to be installed on your operating system.
To achieve this, we will use the pandas library, which provides a high-performance framework for handling tabular data, alongside the openpyxl engine (for .xlsx files) and the xlrd engine (for legacy .xls files).
Environment Setup
Before running the script, make sure you have the required libraries installed in your terminal:
pip install pandas openpyxl xlrd
The Batch Conversion Script
This script handles both modern and legacy extensions, dynamically processes multi-sheet workbooks, and handles special character sets gracefully.
import os
import glob
import pandas as pd
def convert_multiple_excel_to_csv(input_dir, output_dir):
# Ensure output directory exists
os.makedirs(output_dir, exist_ok=True)
# Use glob to scan for all legacy and modern Excel files
excel_extensions = ["*.xlsx", "*.xls", "*.xlsm"]
excel_files = []
for ext in excel_extensions:
excel_files.extend(glob.glob(os.path.join(input_dir, ext)))
print(f"Found {len(excel_files)} Excel workbooks to process.")
for file_path in excel_files:
file_name = os.path.basename(file_path)
base_name, _ = os.path.splitext(file_name)
try:
# Read all sheets at once by setting sheet_name=None
# This returns a dictionary of DataFrames: {sheet_name: dataframe}
excel_dict = pd.read_excel(file_path, sheet_name=None)
for sheet_name, df in excel_dict.items():
# If workbook has only one sheet, keep the base name.
# Otherwise, append sheet name to avoid collisions.
if len(excel_dict) > 1:
csv_file_name = f"{base_name}_{sheet_name}.csv"
else:
csv_file_name = f"{base_name}.csv"
output_path = os.path.join(output_dir, csv_file_name)
# Convert to CSV using standard UTF-8 encoding
df.to_csv(output_path, index=False, encoding='utf-8-sig')
print(f"Successfully exported: {csv_file_name}")
except Exception as e:
print(f"ERROR: Could not convert file {file_name}. Reason: {e}")
if __name__ == "__main__":
# Set your directories here
input_directory = "./my_excel_files"
output_directory = "./converted_csvs"
convert_multiple_excel_to_csv(input_directory, output_directory)
Why pandas is Highly Effective
Using pandas with sheet_name=None is an industry standard because it reads the entire workbook structure as an ordered dictionary. Writing files out with encoding='utf-8-sig' formats the CSV with a Byte Order Mark (BOM). This is a crucial step because if you import these CSVs back into Microsoft Excel later, Excel will immediately recognize the UTF-8 encoding and display special accented letters or foreign currencies correctly.
4. The Quick Windows Shortcut: Converting with PowerShell
If you are on Windows and don't want to write python code or create Excel modules, you can use built-in Command Line tools. PowerShell allows you to convert all excel files in folder to csv by leveraging Windows COM (Component Object Model) scripting.
To run this code, open PowerShell and paste the script after customizing your folder paths:
# Set the input and output directories
$SourceDir = "C:\SourceExcelFiles"
$TargetDir = "C:\TargetCSVFiles"
# Instantiate the Excel Application
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $false
$Excel.DisplayAlerts = $false
# Fetch all Excel files
$ExcelFiles = Get-ChildItem -Path $SourceDir -Filter *.xl*
foreach ($File in $ExcelFiles) {
Write-Host "Processing: $($File.Name)"
$Workbook = $Excel.Workbooks.Open($File.FullName)
$BaseName = [System.IO.Path]::GetFileNameWithoutExtension($File.Name)
for ($i = 1; $i -le $Workbook.Sheets.Count; $i++) {
$Worksheet = $Workbook.Sheets.Item($i)
$SheetName = $Worksheet.Name
# Format filename based on sheet count
if ($Workbook.Sheets.Count -gt 1) {
$OutName = "$($BaseName)_$($SheetName).csv"
} else {
$OutName = "$($BaseName).csv"
}
$DestPath = Join-Path $TargetDir $OutName
# SaveAs parameter 6 represents Comma-Delimited CSV format
$Worksheet.SaveAs($DestPath, 6)
}
$Workbook.Close($false)
}
$Excel.Quit()
# Clean up background system processes
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel) | Out-Null
Remove-Variable Excel
Write-Host "Bulk conversion successfully finalized!" -ForegroundColor Green
Note for System Admins: This command uses Excel under the hood, meaning Excel must be installed on your local computer. It is incredibly efficient for administrators handling quick, on-the-fly desktop automations.
5. The Reverse Flow: Converting Multiple CSV Files to Excel Sheets
Many users executing file formatting tasks face the opposite challenge. Instead of splitting Excel sheets out into separate files, they need to take a massive folder of raw logs or reports and convert multiple csv files to excel sheets, formatting them into single workbooks or individual .xlsx outputs.
We can automate both of these reverse requirements with clean solutions:
Option A: Convert Multiple CSV to XLSX as Individual Files (Python)
If you have dozens of isolated CSVs and need to convert every file to its own discrete .xlsx workbook, you can run this Python script:
import os
import glob
import pandas as pd
def batch_convert_csv_to_xlsx(input_dir, output_dir):
os.makedirs(output_dir, exist_ok=True)
csv_files = glob.glob(os.path.join(input_dir, "*.csv"))
print(f"Found {len(csv_files)} CSV files to convert to XLSX.")
for csv_path in csv_files:
file_name = os.path.basename(csv_path)
base_name = os.path.splitext(file_name)[0]
xlsx_path = os.path.join(output_dir, f"{base_name}.xlsx")
try:
df = pd.read_csv(csv_path)
# Use xlsxwriter engine to save clean formatted files
df.to_excel(xlsx_path, index=False, engine='xlsxwriter')
print(f"Converted: {file_name} -> {base_name}.xlsx")
except Exception as e:
print(f"Failed to process {file_name}: {e}")
Option B: Combine Multiple CSV to Excel Sheets (Python)
If you want to merge separate CSV documents from a directory and place them as worksheets within a single Excel workbook, use the following Python approach. This allows you to combine multiple csv to excel sheets instantly:
import os
import glob
import pandas as pd
def merge_csvs_into_single_workbook(input_folder, output_excel_file):
csv_files = glob.glob(os.path.join(input_folder, "*.csv"))
if not csv_files:
print("No CSV files found.")
return
# Initialize a Pandas Excel writer
with pd.ExcelWriter(output_excel_file, engine='openpyxl') as writer:
for file_path in csv_files:
file_name = os.path.basename(file_path)
sheet_name = os.path.splitext(file_name)[0]
# Excel limits sheet names to a maximum of 31 characters
safe_sheet_name = sheet_name[:30]
# Read CSV and write to the target tab
df = pd.read_csv(file_path)
df.to_excel(writer, sheet_name=safe_sheet_name, index=False)
print(f"Integrated '{file_name}' into sheet: '{safe_sheet_name}'")
print(f"Successfully compiled workbook: {output_excel_file}")
Option C: Code-Free CSV Merging via Power Query
If you want to combine CSV files into a consolidated workbook without using code, Excel's modern Power Query tool is extremely effective:
- Open a new Excel workbook.
- Navigate to the Data tab.
- Click Get Data > From File > From Folder.
- Browse to the folder holding your multiple CSV files and click Open.
- Excel will show a list of metadata for your files. Click the Combine dropdown and select Combine & Transform Data.
- Select the delimiter (typically Comma) and click OK.
- Click Close & Load to pull the merged contents directly into an organized sheet.
Power Query is dynamic. If you drop more CSV files into that folder in the future, you can simply click Data > Refresh All to update your output instantly.
6. Overcoming Common Data Pitfalls during Batch Conversions
While automating conversions is relatively straightforward, preserving data integrity presents several hidden issues. When performing bulk file operations, watch out for these standard data traps:
1. Character Encoding Disasters
If your files contain special characters, names with accents, currency formats, or foreign languages, a standard conversion may render them as broken characters (e.g., "é"). Always enforce UTF-8 with BOM (Byte Order Mark). In Python, write with encoding='utf-8-sig'. In VBA or PowerShell, use explicit UTF-8 parameters to ensure compatibility across both Mac and Windows platforms.
2. Dropped Leading Zeros
If you have columns containing numerical identifiers with leading zeros, such as US zip codes ("02108") or international product IDs, Excel defaults to treating them as general numbers and truncates them ("2108"). If you use Python to convert, ensure you specify string datatypes (dtype=str) on key columns to prevent truncation during read/write cycles:
# Force specific columns to remain text strings
df = pd.read_csv('data.csv', dtype={'ZipCode': str, 'ProductID': str})
3. Delimiter Collisions
CSV files default to commas, but European markets often use semicolons (;) because they use commas as decimal separators. Check your input formats. If you attempt to convert comma-separated files that contain native sentence formatting with commas, ensure text qualifiers like double quotes (") surround the text blocks. This prevents parser errors and accidental row-splitting.
4. Dates as Serial Integers
Excel stores dates internally as floating-point serial numbers representing the count of days since January 1, 1900. If you encounter raw integer conversions (like "44231" instead of "2021-02-04"), use formatting functions during import or explicitly declare column parsing in Pandas using parse_dates=True.
7. Frequently Asked Questions
How can I convert thousands of XLS files to CSV without having Microsoft Excel installed?
Using the Python method outlined in Section 3 is the ideal approach. Python’s pandas library uses underlying C and C++ libraries (like openpyxl and xlrd) to open, read, and write file systems directly. It operates completely independently of any local MS Office installation, making it highly suitable for Linux servers or cloud environments.
What is the absolute fastest method to convert 10,000 files?
Python with concurrent processing is the fastest setup. By incorporating Python's built-in multiprocessing or concurrent.futures modules, you can distribute file conversion tasks across all available CPU cores, allowing you to convert thousands of sheets in seconds.
Why does my CSV file format only save a single sheet when I convert a workbook?
By design, the Comma-Separated Values file standard is a 2D flat file. It does not contain tabs, sheets, layouts, or workbook relationships. To save multiple sheets to CSV, you must export every worksheet to its own isolated file, using a programmatic process like our VBA script or Python methods.
How can I make sure my special characters aren't corrupted during conversion?
Use UTF-8 with a Byte Order Mark (BOM). When saving CSV files using Python, apply encoding='utf-8-sig'. In Excel, ensure you specifically choose CSV UTF-8 (comma delimited) (*.csv) from the drop-down menu rather than the basic legacy CSV option.
Can I merge multiple CSVs into a single Excel file?
Yes, this is very common. You can use Python with pd.ExcelWriter to write each CSV to its own tab. Alternatively, you can use Excel's built-in Power Query ("From Folder" tool) to combine and load multiple CSV files into your workbook without writing code.
Summary of Methods: Which Should You Use?
| Your Goal | Recommended Method | Requirements | Best For |
|---|---|---|---|
| Convert files via desktop UI | Excel VBA Macro | Excel Installed | Non-technical users, local office files |
| Deploy conversion in server / data pipeline | Python Script (pandas) |
Python, pandas installed |
Software engineers, data analysts, cross-platform workflows |
| Administrative local system scripting | Windows PowerShell | Windows OS, Excel | Sysadmins, quick Windows terminal execution |
| Combine CSVs without writing any code | Power Query | Excel 2016 or newer | Casual users, simple merging tasks |
By matching the right tool to your scale and technical workflow, you can handle any complex bulk file conversion with ease.









