跳到主要內容

如何在Excel中將每個工作表另存為CSV / PDF文件?

例如,您有一個包含多個工作表的大型工作簿,並且想要將每個工作表保存或導出為單獨的.csv文件或PDF文件,如何輕鬆快速地完成工作? 在本文中,我將介紹幾種解決方法。


使用另存為功能將每個工作表保存或導出為CSV / PDF文件

如您所知,Microsoft Excel可以將當前工作表另存為單個.csv文件或PDF文件。 因此,您可以手動將每張圖紙分別保存或導出為.csv文件或PDF文件。

1.切換到要保存或導出為單個.csv文件的工作表,然後單擊 文件 辦公按鈕)> 另存為.

2.在打開的對話框中,指定要將.csv文件保存到的目標文件夾,然後單擊 保存類型 框並選擇 CSV(以逗號分隔)(* .csv) or PDF(* .pdf) 從下拉列表中,然後單擊 節省 按鈕。

3.將會連續出現兩個警告對話框。 請點擊 OK > .

注意: 如果將活動工作表另存為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實用程序。

Excel的Kutools - 使用 300 多種基本工具增強 Excel 功能。 享受全功能 30 天免費試用,無需信用卡! 立即行動吧!

1。 點擊 企業 > 工作簿 > 拆分工作簿.

doc每個工作表到csv 2

2.在打開的“拆分工作簿”對話框中,

doc每個工作表到csv 8

(1)繼續選擇所有紙張。 如果沒有,您可以在之前選中該複選框 工作表名稱 選擇所有工作表;

(2)檢查 指定保存格式 選項;

(3)點擊下面的框 指定保存格式 選項,然後選擇 CSV(Macintosh)(*。csv) or PDF(* .pdf) 從下拉列表中。

(4)點擊 分裂 按鈕。

 

備註:如果工作簿中存在隱藏的空白工作表,請檢查 跳過隱藏的工作表 盒子和 跳過空白工作表 框在導出時將忽略所有空白或隱藏的工作表。

Excel的Kutools - 使用 300 多種基本工具增強 Excel 功能。 享受全功能 30 天免費試用,無需信用卡! 立即行動吧!

3.在打開的瀏覽文件夾對話框中,指定要將所有.csv文件或PDF文件保存到的目標文件夾,然後單擊 OK 按鈕。

現在,您將看到每個工作表都已導出,並另存為指定文件夾中的.csv文件。


演示:在Excel中將每個工作表保存或導出為CSV / PDF文件


Excel的Kutools:超過 300 個方便的工具觸手可及! 立即開始 30 天免費試用,沒有任何功能限制。 現在就下載!

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為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