提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何保存,导出多个/所有工作表在Excel中分隔CSV或文本文件?

在使用Excel时,您可以通过另存为功能手动将工作表保存为csv或文本文件。 但是,要将工作簿中的多个或全部工作表转换为单独的csv或文本文件,您该如何操作? 在本文中,我们将向您展示将多个或全部工作表保存或转换为分隔的csv或文本文件的方法。

使用VBA代码保存,导出或转换所有工作表到csv或文本文件

使用Kutools for Excel保存,导出或转换多个/所有工作表到csv或文本文件


您可能感兴趣的是:

将多个工作表/工作簿合并到一个工作表/工作簿中:

将多个工作表或工作簿合并到一个工作表或工作簿中可能是您​​日常工作中的一项重大任务。 但是,如果你有 Kutools for Excel,其强大的效用 - 结合 可以帮助您将多个工作表,工作簿快速合并到一个工作表或工作簿中。

Kutools for Excel 包含了比300更方便的Excel工具。 免费试用30天无限制。 现在免费下载

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

箭头蓝色右泡 使用VBA代码保存,导出或转换所有工作表到csv或文本文件


使用下面的VBA代码,可以将工作簿中的所有工作表保存为分隔的csv或文本文件。 请做如下。

将所有工作表导出或转换为CSV文件

1。 按 其他 + F11 键同时打开 Microsoft Visual Basic应用程序 窗口。

2。 在里面 Microsoft Visual Basic应用程序 窗口中,单击 插页 > 模块。 然后将以下代码复制并粘贴到 模块 窗口。

VBA代码:将所有工作表导出到分离的csv文件

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。 按 F5 键来运行代码。 您会看到所有导出的csv文件都位于 需要上传的文件 夹。 看截图:

将所有图纸导出或转换为文本文件

以下代码可以帮助您将工作簿中的所有工作表导出或转换为单独的文本文件。

VBA代码:将所有页面导出到单独的文本文件

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

导出的文本文件也位于 需要上传的文件 夹。 看截图:


箭头蓝色右泡 使用Kutools for Excel保存,导出或转换多个/所有工作表到csv或文本文件

You可以快速导出或转换多个或所有工作表到单独的csv文件,文本文件或xls文件格式在Excel中与 分割工作簿 实用程序 Kutools for Excel.

Kutools for Excel :与超过300方便的Excel加载项, 免费试用60天无限制.

1。 点击 企业服务 > 工作簿 > 分割工作簿。 看截图:

2。 在里面 分割工作簿 对话框:

1)。 如果要将所有工作表转换为csv或文本文件,只需在所有工作表中检查所有工作表名称 工作表名称 框; 如果您只想转换多张纸,请继续检查并取消选中您不想转换的其他纸张。

2)。 在里面 期权 部分,检查 保存类型 框,然后选择 Unicode文本(* .txt) or CSV(Macintosh)(* .csv) 从下拉列表中选择。

3)。 点击 分裂 按钮。

3。 在里面 浏览文件夹 对话框中,指定一个文件夹来保存导出的文件,然后单击 OK 按钮。

现在,所有工作表或指定工作表都将转换为单独的csv或文本文件,并按上面指定的方式在文件夹中找到。


箭头蓝色右泡 使用Kutools for Excel保存,导出或转换多个/所有工作表到csv或文本文件

Kutools for Excel 包含了比300更方便的Excel工具。 免费试用60天无限制。 立即下载免费试用!


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
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.
    Tarah Collins · 1 days 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 · 6 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 · 1 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!