Split Each Excel Sheet Into a Separate File With Python
This Python script opens a workbook with xlwings, copies each worksheet into a new workbook and saves it in an Output folder, named after the sheet. Because xlwings drives Excel itself, formatting, formulas and charts come along. A second version splits every workbook in a folder. You need Excel installed on Windows or Mac.
Install xlwings
The script needs one package, xlwings, and the desktop version of Excel. pathlib, which builds the file paths, comes with Python.
pip install xlwings
The script
Save the script next to your workbook, change YOUR_EXCEL_FILE.xlsx to your file name and run it. Each worksheet ends up as its own workbook in the Output folder.
from pathlib import Path
import xlwings as xw # pip install xlwings
EXCEL_FILE = Path(__file__).parent / 'YOUR_EXCEL_FILE.xlsx'
OUTPUT_DIR = Path(__file__).parent / 'Output'
# Create Output directory
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
with xw.App(visible=False) as app:
wb = app.books.open(EXCEL_FILE)
for sheet in wb.sheets:
wb_new = app.books.add()
sheet.copy(after=wb_new.sheets[0])
wb_new.sheets[0].delete()
wb_new.save(OUTPUT_DIR / f'{sheet.name}.xlsx')
wb_new.close()

How it works
The paths are built from the script’s own folder, so it does not matter where you start Python from. xw.App(visible=False) starts a hidden Excel instance, and because it is used as a context manager, Excel quits even if something fails halfway.
For each sheet, the script adds a new workbook, copies the sheet after its first sheet, deletes that empty first sheet, saves the file under the sheet name and closes it again to free memory.
Split every workbook in a folder
For a whole folder of workbooks, loop over the files first. rglob("*.xls*") finds .xlsx, .xlsm and .xls files in the folder and all its subfolders. The output name combines the file name and the sheet name, so two files with a “Jan” sheet do not overwrite each other.
from pathlib import Path
import xlwings as xw # pip install xlwings
BASE_DIR = Path(__file__).parent
INPUT_DIR = BASE_DIR / "Files" # !!! CHANGE THE FILEPATH !!!
OUTPUT_DIR = BASE_DIR / "Output"
# Create Output directory
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
files = list(INPUT_DIR.rglob("*.xls*"))
with xw.App(visible=False) as app:
for file in files:
wb = app.books.open(file)
for sheet in wb.sheets:
wb_new = app.books.add()
sheet.copy(after=wb_new.sheets[0])
wb_new.sheets[0].delete()
wb_new.save(OUTPUT_DIR / f"{file.stem}_{sheet.name}.xlsx")
wb_new.close()
For more on glob versus rglob, see how to loop through folders and subfolders in Python. To group sheets with the same name from several files into one workbook instead, use the script in group Excel sheets and save them as separate workbooks. To split one sheet by the values in a column, for example one file per country, see how to split Excel data into multiple files by column values.
Troubleshooting
Most failures come from files that are still open in Excel, formulas that point to other sheets, or a machine without Excel.
- The workbook is open in Excel. Close it first. A file that is open in another Excel window can open as read-only or block the script.
- A file with that name already exists and is open. Excel cannot overwrite an open file, so close the old output files before you run the script again.
- Formulas point to other sheets. A copied sheet keeps formulas that refer to sheets in the original workbook, so those cells become external links. Convert the formulas to values first if you need clean files. I show how in convert all Excel formulas into values with Python.
- It only runs on Windows or Mac with Excel installed. xlwings drives the Excel application, so it does not work on a server without Excel.
