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

or

How to save, export multiple/all sheets to separate csv or text files in Excel?

While using Excel, you can manually save a worksheet as a csv or text file by Save As function. However, for converting multiple or all sheets in a workbook to separated csv or text file, how can you do? In this article, we will show you methods of saving or converting multiple or all sheets to separated csv or text file.

Save, export or convert all sheets to csv or text file with VBA code

Save, export or convert multiple/all sheets to csv or text file with Kutools for Excel


You may interest in:

Combine multiple worksheets/workbooks into one worksheet / workbook:

Combine multiple worksheets or workbooks into one single worksheet or workbook may be a huge task in your daily work. But, if you have Kutools for Excel, its powerful utility – Combine can help you quickly combine multiple worksheets, workbooks into one worksheet or workbook.

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 30 days. Free Download Now

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

arrow blue right bubble Save, export or convert all sheets to csv or text file with VBA code


With the below VBA codes, you can save all worksheets in a workbook to separated csv or text files. Please do as follows.

Export or convert all sheets to csv files

1. Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic Application window.

2. In the Microsoft Visual Basic Application window, click Insert > Module. Then copy and paste the following code into the Module window.

VBA code: Export all sheets to separated csv files

Sub ExportSheetsToCSV()
	Dim xWs As Worksheet
	Dim xcsvFile As String
	For Each xWs In Application.ActiveWorkbook.Worksheets
		xWs.Copy
		xcsvFile = CurDir & "\" & xWs.Name & ".csv"
		Application.ActiveWorkbook.SaveAs Filename: = xcsvFile, _
		FileFormat: = xlCSV, CreateBackup: = False
		Application.ActiveWorkbook.Saved = True
		Application.ActiveWorkbook.Close
	Next
End Sub

3. Press the F5 key to run the code. You will see all exported csv files are located on the Documents folder. See screenshot:

Export or convert all sheets to Text files

The following code can help you to export or convert all sheets in workbook to separated Text files.

VBA code: Export all sheets to separated Text files

Sub ExportSheetsToText()
	Dim xWs As Worksheet
	Dim xTextFile As String
	For Each xWs In Application.ActiveWorkbook.Worksheets
		xWs.Copy
		xTextFile = CurDir & "\" & xWs.Name & ".txt"
		Application.ActiveWorkbook.SaveAs Filename: = xTextFile, FileFormat: = xlText
		Application.ActiveWorkbook.Saved = True
		Application.ActiveWorkbook.Close
	Next
End Sub

The exported Text files are also located on the Documents folder. See screenshot:


arrow blue right bubble Save, export or convert multiple/all sheets to csv or text file with Kutools for Excel

You can quickly export or convert multiple or all sheets to individual csv files, text files or xls files format in Excel with the Split Workbook utility of Kutools for Excel.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 60 days.

1. Click Enterprise > Workbook > Split Workbook. See screenshot:

2. In the Split Workbook dialog box:

1). If you want to convert all sheets to csv or text files, just keep all sheet names checked in the Worksheet name box; If you just want to convert multiple sheets, keep checking them and going to uncheck other sheets you don’t want to convert.

2). In the Options section, check the Save as type box and then select Unicode Text(*.txt) or CSV (Macintosh)(*.csv) from the drop-down list.

3). Click the Split button.

3. In the Browse For Folder dialog box, specify a folder to save the exported files, and then click the OK button.

Now all sheets or specified sheets are converted to separated csv or text files, and locate on the folder as you specified above.


arrow blue right bubble Save, export or convert multiple/all sheets to csv or text file with Kutools for Excel

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 60 days. Download the free trial now!


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

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!
officetab bottom
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.
    nathan · 7 days ago
    how would I change the code to have it save in a different file format such as an xlsx? or ASCII.
  • To post as a guest, your comment is unpublished.
    Francia · 2 months ago
    So, this is great! BUT, what if I need to split a workbook into .csv but for PC, not MAC? If anyone has a way of doing it, please help me out. I will be very grateful.
  • To post as a guest, your comment is unpublished.
    Tarah Collins · 2 months ago
    Is there a way to use this code to export only a certain range to a .csv file of each sheet in a book?
  • To post as a guest, your comment is unpublished.
    Mirko · 9 months ago
    Hello,
    thank you so much for a great macro, it works like a charm! But I have a question, what if I would like to save this macro (CSV version) on PERSONAL.xlsb as to make it available on any excel instance?

    When I try, CurDir takes the PERSONAL directory, instead of the active worksheet one...

    Thank you for any help!
  • To post as a guest, your comment is unpublished.
    AK sharma · 1 years ago
    If you just want to convert multiple sheets, keep checking them and going to uncheck other sheets you don’t want to convert
    sir for thuis step do you have macro
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good day,
      Can't help with VBA code for this. Why not try the Split Workbook utility we provide in the post? It will save your time and you will love it.
  • To post as a guest, your comment is unpublished.
    sai · 1 years ago
    Superb solution.....Its saved my time.......Thank you
  • To post as a guest, your comment is unpublished.
    Cameron Stewart · 1 years ago
    Thanks - script very useful
  • To post as a guest, your comment is unpublished.
    Ken · 1 years ago
    A, I see now that the line "VBA code: Export all sheets to separated csv files" should not be copied into the code area. Perhaps that can be more explicit for newbies, and for people who follow instructions explicitly.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Ken,
      That's the description line of the code. The line "Sub ExportSheetsToCSV()" should be the first line of the code.
      I'm sorry for the inconvenience.
  • To post as a guest, your comment is unpublished.
    R · 1 years ago
    1) I have a workbook with multiple sheets in it.
    2) Those multiple sheets are having multiple columns.
    3) I have one column in each sheet which is concatenation of all the other columns.
    4) Now, I want to extract that concatenated column to a text file with the same name as sheet name.
    5) The way I want is I just press one button and it should look for all the tabs, extract that column (say concatenated column is AA) from each sheet, put that into a text file, name the text file same as sheet name and store in some directory on my desktop say H drive.
  • To post as a guest, your comment is unpublished.
    Abhishek Jha™ · 1 years ago
    I need a macro to convert all the tabs in a excel file to different set of files.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good Day,
      Which files do you want to include in your "different set of files"?
  • To post as a guest, your comment is unpublished.
    Tauseef Kundalia · 2 years ago
    hi i need a macro which convert pipe "|" separated csv into xlsx asking folder name not a single file. i need it on urgent basis.


    Regards,
  • To post as a guest, your comment is unpublished.
    ashish · 2 years ago
    hello alex please could you display the code to save the files in csv format except the documents folder
  • To post as a guest, your comment is unpublished.
    Amit Chaudhary · 2 years ago
    Hi,
    Thanks for the code, I just have a small clarification. Currently when the CSV file generates it's delimited by comma ",". even though my system setting is for CSV the delimited should be pipe "|". Not sure why the CSV is generated with comma delimiter with the above code. Is there a way i can explicitly define the delimiter for the CSV file.

    Looking for your reply soonest.
    Thank.
    Regards,
    Amit
  • To post as a guest, your comment is unpublished.
    Tallrific · 2 years ago
    I'm writing to determine if your application can convert multiple xls sheets to one text file and how it would order the rows. I need to have an option to order the rows in order of appearance, one line at a time one sheet at a time. Sheet 1, row 1; sheet 2, row 1, sheet 3, row1, etc. I look forward to your feedback.
  • To post as a guest, your comment is unpublished.
    Mike · 3 years ago
    Thanks for the macros, they were just what I needed.
    However, using "CurDir" to build the output filepath is very dangerous as it is not necessarily the folder of the Excel file that was opened - it is generally the current folder in explorer so your files could end up getting written practically anywhere. You should use Application.ThisWorkbook.Path instead.
  • To post as a guest, your comment is unpublished.
    Nicolas · 3 years ago
    Hi, thank you for the code, is it possible to skip some sheets and only save a few?
    I've got no idea how I should start. Could you help me?

    Nicolas
  • To post as a guest, your comment is unpublished.
    Alex K123456789 · 3 years ago
    Is there any way to have the CSV files save to a folder other than the Documents folder?
    • To post as a guest, your comment is unpublished.
      Paul · 3 years ago
      [quote name="Alex K123456789"]Is there any way to have the CSV files save to a folder other than the Documents folder?[/quote]
      I haven't tested it, but I'm pretty the "\" in this line stands for the working directory: xcsvFile = CurDir & "\" & xWs.Name & ".csv"
      If you want to change the working directory, you'll have to add another command.
      If you want to save it to a folder within the working directory, say in a folder called new you just replace "\" with "\New\".
      Something along those lines.
      • To post as a guest, your comment is unpublished.
        ALEX K123456789 · 3 years ago
        Thank you very much Paul. I wound up figuring it out a little while back, but your solution is exactly what I did.
        • To post as a guest, your comment is unpublished.
          Dawn · 2 years ago
          Hi Alex,
          Could you show me the line of code you entered in place of the "\" please? I need to be able to save these .csv files to a location on our network rather than in my local WS library. We need to allow our Customer Service people to be able to access the file and rename the location each time it is used.
          I encounter bug problems with simply changing "\" to "\New\" (the VBA code does work as expected when copied straight from the info above). I am not code saavy, but I can follow directions fairly well, so any help is appreciated!
          • To post as a guest, your comment is unpublished.
            Alex K123456789 · 2 years ago
            [quote name="Dawn"]Hi Alex,
            Could you show me the line of code you entered in place of the "\" please? I need to be able to save these .csv files to a location on our network rather than in my local WS library. We need to allow our Customer Service people to be able to access the file and rename the location each time it is used.
            I encounter bug problems with simply changing "\" to "\New\" (the VBA code does work as expected when copied straight from the info above). I am not code saavy, but I can follow directions fairly well, so any help is appreciated![/quote]

            Hi Dawn, I wound up having to re-write portions and like Paul suggested, used a slightly different command. Below is the command I wrote to refresh the data in my workbook from our Data Warehouse, then refresh pivot tables and ultimately save one of the sheets as a PDF to my drive:

            ActiveWorkbook.RefreshAll
            Sheets("Karth").Select
            Range("B22").Select
            ActiveSheet.PivotTables("Karth_Appd_Wkly").PivotCache.Refresh
            Sheets("Start").Select
            Sheets("Karth").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "K:\K\Analytics\Reports\Sales\SM Reports\SM Summary_Karth.pdf" _
            , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
            End Sub
        • To post as a guest, your comment is unpublished.
          Paul · 3 years ago
          Nice! Thanks for the reply, it also means a lot to me to know that my solution is the correct one. Cheers!