How to extract sheet from multiple *.xlsm and save it as *.csv or txt in Python?

My requirement is exactly matching with below post from "StackOverflow". This code snippet works perfectly for only one excel file (workbook = xlrd.open_workbook('test.xlsx')) but I have more than 100 + excel files with same Sheet name across all the excel macro files.

Can someone please modify the code, which can create multiple files with different name

import csv
import xlrd

workbook = xlrd.open_workbook('test.xlsm')
for sheet in workbook.sheets():
    if == "Sheet_name_from_xlsm_file":
        with open('{}.csv'.format(, 'w') as f:
            writer = csv.writer(f)
            for row in range(sheet.nrows):
                out = []
                for cell in sheet.row_values(row):

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Do you want to save the data from the specified sheet in each xlsm file to it's own CSV/text file or should all the data go in the one file?

Where will all the source files be located?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IdleGuysAuthor Commented:
Hi Norie, Apologies for delay response. I was looking to extract the data to different files (csv or txt or sql) files with excel name as file name. I have completed this today with help from my team. It is working perfectly.

Thanks for your time, closing this post.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.