跳到主要内容

如何在Excel中将每个工作表另存为CSV / PDF文件?

例如,您有一个包含多张工作表的大型工作簿,并且想要将每张工作表保存或导出为单独的.csv文件或PDF文件,如何轻松快速地完成工作? 在本文中,我将介绍几种解决方法。


使用另存为功能将每个工作表保存或导出为CSV / PDF文件

如您所知,Microsoft Excel可以将当前工作表另存为单个.csv文件或PDF文件。 因此,您可以手动将每张图纸分别保存或导出为.csv文件或PDF文件。

1.切换到要保存或导出为单个.csv文件的工作表,然后单击 文件 (或 办公按钮)> 另存为.

2.在打开的对话框中,指定要将.csv文件保存到的目标文件夹,然后单击 保存类型 框并选择 CSV(以逗号分隔)(* .csv) or PDF(* .pdf) 从下拉列表中,然后单击 保存 按钮。

3.将会连续出现两个警告对话框。 请点击 OK > USB MIDI(XNUMX通道).

请注意: 如果将活动工作表另存为PDF文件,则不会弹出这些对话框。 只需继续下一步即可。

4.重复上述步骤1-3,将其他工作表一张一张保存为单独的.csv文件。


使用VBA批量保存或将每个工作表导出为CSV文件

如果有许多工作表要保存或导出为.csv文件,则第一种方法将非常耗时且乏味。 此VBA可以简化工作,并易于将每张图纸保存或导出为.csv文件。

1。 按 其他 + F11 同时按下键以打开“ Microsoft Visual Basic for Application”窗口。

2。 点击 插页 > 模块,然后将以下VBA代码粘贴到新的模块窗口中。

VBA:将每个工作表另存为单独的CSV文件

Public Sub SaveWorksheetsAsCsv()
Dim xWs As Worksheet
Dim xDir As String
Dim folder As FileDialog
Set folder = Application.FileDialog(msoFileDialogFolderPicker)
If folder.Show <> -1 Then Exit Sub
xDir = folder.SelectedItems(1)
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.SaveAs xDir & "\" & xWs.Name, xlCSV
Next
End Sub
3。 点击 运行 按钮或按下 F5 运行此VBA的关键。

4.在打开的浏览对话框中,指定要将所有.csv文件保存到的目标文件夹,然后单击 OK 按钮。

然后,您将看到每个工作表都作为单独的.csv文件保存/导出到指定的目标文件夹中。


使用 Kutools for Excel 批量保存或导出每个工作表为 CSV/PDF 文件

一些Excel用户出于某些原因可能会拒绝VBA代码。 别担心! 第三种方法还可以轻松地将每个工作表批量保存或导出为.csv文件或PDF文件。 拆分工作簿 Kutools for Excel 的实用程序。

Kutools for Excel - 使用 300 多种基本工具增强 Excel 功能。 享受全功能 30 天免费试用,无需信用卡! 立即行动吧!

1。 点击 企业 > 工作簿 > 拆分工作簿.

doc每个工作表到csv 2

2.在打开的“拆分工作簿”对话框中,

doc每个工作表到csv 8

(1)继续选择所有纸张。 如果没有,您可以在之前选中该复选框 工作表名称 选择所有工作表;

(2)检查 指定保存格式 选项;

(3)点击下面的框 指定保存格式 选项,然后选择 CSV(Macintosh)(*。csv) or PDF(* .pdf) 从下拉列表中。

(4)点击 分裂 按钮。

 

备注:如果工作簿中存在隐藏的空白工作表,请检查 跳过隐藏的工作表 盒子和 跳过空白工作表 导出时,该框将忽略所有空白或隐藏的工作表。

Kutools for Excel - 使用 300 多种基本工具增强 Excel 功能。 享受全功能 30 天免费试用,无需信用卡! 立即行动吧!

3.在打开的浏览文件夹对话框中,指定要将所有.csv文件或PDF文件保存到的目标文件夹,然后单击 OK 按钮。

现在,您将看到每个工作表都已导出,并另存为指定文件夹中的.csv文件。


演示:在Excel中将每个工作表保存或导出为CSV / PDF文件


Kutools for Excel:超过 300 个方便的工具触手可及! 立即开始 30 天免费试用,没有任何功能限制。 立即下载!

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you so much - the VBA soultion worked great and saved me a ton of time!
This comment was minimized by the moderator on the site
Hello, thank you for these tips! I tried using the VBA code but I'm getting a run-time error code 91 for the following syntax:

If folder.Show <> -1 Then Exit Sub

Can you help me troubleshoot? I'm new to VBA. :)
This comment was minimized by the moderator on the site
Hi there,

Please make sure that there is only the VBA code from this tutorial in your Module window. If there are other codes, please delete or move them to a new module.

After that, please run the code. If it's still not working, please use the code below:
Public Sub SaveWorksheetsAsCsv()
Dim xWs As Worksheet
Dim xDir As String
Dim folder As FileDialog
On Error Resume Next
Set folder = Application.FileDialog(msoFileDialogFolderPicker)
If folder.Show <> -1 Then Exit Sub
xDir = folder.SelectedItems(1)
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.SaveAs xDir & "\" & xWs.Name, xlCSV
Next
End Sub


Amanda
This comment was minimized by the moderator on the site
How to keep and maintain decimals values when exporting excel sheets to CSV? financial data requires accuracy of data till 3 decimals when export to CSV? please advise
This comment was minimized by the moderator on the site
Hi prashan9810,
Before exporting the sheets from Excel to CSV, you’d better change the formatting of currency numbers, and fix their decimal places to 3.
You can change the decimal places as follows:
1. In Excel, select the currency cells, right click, and select Format Cells from the context menu.
2. In the Format Cells dialog, select Currency or Accounting in the Category list box, enter 3 in the Decimal places box, and click OK.
This comment was minimized by the moderator on the site
Thank you for your very helpful tips. I used the vba code to convert an excel file with multiple sheets into individual csv files. I'm wondering, how can I specify that i'd like those csv files to be utf-8? Is there an addition to the code below that will add that feature? Public Sub SaveWorksheetsAsCsv() Dim xWs As Worksheet Dim xDir As String Dim folder As FileDialog Set folder = Application.FileDialog(msoFileDialogFolderPicker) If folder.Show -1 Then Exit Sub xDir = folder.SelectedItems(1) For Each xWs In Application.ActiveWorkbook.Worksheets xWs.SaveAs xDir & "\" & xWs.Name, xlCSV Next End Sub
This comment was minimized by the moderator on the site
ActiveWorkbook.SaveAs Filename:=Replace(Replace(xSPath & xCSVFile & xWs.Name, ".xlsx", "", vbTextCompare), ".xls", "", vbTextCompare) & ".csv", FileFormat:=xlCSVUTF8, CreateBackup:=False
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations