跳到主要內容

如何在Excel中將每個工作表導出並另存為單獨的新工作簿?

假設您要導出一個或幾個工作表並將其另存為新工作簿,您將如何處理? 通常,您可以復制每個工作表並粘貼到新工作簿中。 但是在這裡,我們為您帶來一些方便的技巧來應對它:

使用“移動”或“複製”命令將工作表導出並保存為新工作簿

使用VBA代碼將工作表導出並另存為新工作簿

使用Kutools for Excel將工作表導出並保存為新工作簿 好主意3


箭頭藍色右氣泡 使用“移動”或“複製”命令將工作表導出並保存為新工作簿

使用 移動或複制 命令將幫助您快速將一個或幾個工作表導出或複製到新工作簿。

步驟1:在選項卡欄中選擇工作表名稱。 您可以按住來選擇多個 按Ctrl 鍵或 鍵。

步驟2:右鍵單擊工作表名稱,然後單擊 移動或複制 從上下文菜單中。
doc導出表1

步驟3: 移動或複制 對話框中,選擇 (新書) 的下拉列表中的項目 將選定的圖紙移到書上.

doc導出表2

步驟4:然後點擊 OK,現在您已切換到 新工作簿 與導出或複制的工作表,單擊 文件 > 節省 保存新的工作簿。

注意:移動或複制 對話框中,有一個 建立副本 選項。 如果您不選中它,它將把選定的工作表移出原始工作簿; 如果選中它,它將復制所選的工作表。


快速將多個工作表拆分為Excel中的單獨工作簿

在Microsoft Excel中,可以通過將工作表複製並粘貼到新工作簿中,將一個工作簿中的工作表保存或拆分為新的Excel文件。 如果要將大工作簿的每個工作表/工作表拆分為單獨的Excel,txt,csv,pdf文件,這似乎很麻煩。 但是隨著 Excel的Kutools拆分工作簿 實用程序,您可以快速處理它。  點擊即可免費試用 30 天,享受全部功能!
doc拆分工作簿1
 
Kutools for Excel:擁有300多個便捷的Excel加載項,可以在30天內免費試用。

箭頭藍色右氣泡 使用VBA代碼將工作表導出並另存為新工作簿

下面的代碼將導出新工作簿中的每個可見工作表,並將工作表和原始工作表的名稱保存在與活動工作簿相同路徑的新創建的文件夾中。 請執行以下步驟:

步驟1:按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

步驟2:點擊 插入 > 模塊,然後將以下宏粘貼到“模塊窗口”中:

VBA:將工作表導出並保存為新工作簿,並保存在新文件夾中。

Sub SplitWorkbook()
'Updateby20200806
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim xWs As Worksheet
Dim xWb As Workbook
Dim xNWb As Workbook
Dim FolderName As String
Application.ScreenUpdating = False
Set xWb = Application.ThisWorkbook

DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = xWb.Path & "\" & xWb.Name & " " & DateString

If Val(Application.Version) < 12 Then
    FileExtStr = ".xls": FileFormatNum = -4143
Else
    Select Case xWb.FileFormat
        Case 51:
            FileExtStr = ".xlsx": FileFormatNum = 51
        Case 52:
            If Application.ActiveWorkbook.HasVBProject Then
                FileExtStr = ".xlsm": FileFormatNum = 52
            Else
                FileExtStr = ".xlsx": FileFormatNum = 51
            End If
        Case 56:
            FileExtStr = ".xls": FileFormatNum = 56
        Case Else:
            FileExtStr = ".xlsb": FileFormatNum = 50
        End Select
End If

MkDir FolderName

For Each xWs In xWb.Worksheets
On Error GoTo NErro
    If xWs.Visible = xlSheetVisible Then
    xWs.Select
    xWs.Copy
    xFile = FolderName & "\" & xWs.Name & FileExtStr
    Set xNWb = Application.Workbooks.Item(Application.Workbooks.Count)
    xNWb.SaveAs xFile, FileFormat:=FileFormatNum
    xNWb.Close False, xFile
    End If
NErro:
    xWb.Activate
Next

    MsgBox "You can find the files in " & FolderName
    Application.ScreenUpdating = True
End Sub

步驟3:按下 F5 運行此代碼的關鍵。 然後將彈出一個提示框,告訴您新導出的工作簿的位置,並且原始工作簿的所有工作表均已導出到一些新的單獨工作簿中,這些工作簿在新的特定文件夾中命名了原始工作表。 查看屏幕截圖:

doc導出表7

箭頭藍色右氣泡 使用Kutools for Excel將工作表導出並保存為新工作簿

如果需要將多個工作表另存為單獨的工作簿,則第一種方法不是一個好的選擇。 對於Excel初學者來說,VBA代碼可能有點複雜。 在這裡您可以使用 拆分工作簿 的效用 Excel的Kutools 以快速輕鬆地導出並保存一個工作簿的每個工作表以分離新工作簿。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

免費安裝 Kutools for Excel,請執行以下操作:

步驟1:點擊 Kutools 加 > 工作簿 > 拆分工作簿…。 看截圖:
doc導出表3

步驟2:在 拆分工作簿 對話框,請執行以下操作:

doc導出表4
1: 默認情況下,所有工作表名稱均已選中,如果您不想拆分某些工作表,則可以取消選中它們;


2: 如果要避免拆分隱藏的工作表或空白工作表,可以檢查 跳過隱藏的工作表 or 跳過空白工作表);


3: 你也可以檢查 指定保存 格式,並選擇拆分工作表,然後以默認格式另存為文本文件,pdf文件或csv文件,如果不選中此選項,它將拆分工作表並另存為工作簿。

步驟3:然後點擊 分裂 按鈕,然後選擇要將新工作簿放入的文件夾。 看截圖:
doc導出表6

步驟4:然後點擊 OK,然後在 拆分工作簿 對話框被導出並保存為單獨的工作簿。 每個新工作簿均使用原始工作表名稱命名。 看截圖:
doc導出表5

單擊以了解有關此拆分工作簿工具的更多信息.

箭頭藍色右氣泡 導出並將每個工作表另存為新工作簿


根據Excel中的列或固定行將數據快速拆分為多個工作表

假設您有一個工作表,該工作表的數據在A到G列中,推銷員的名字在A列中,並且您需要根據同一工作簿中的A列將這些數據自動拆分為多個工作表,並且每​​個推銷員都會被拆分為一個新的工作表。 Excel的Kutools拆分日期 實用程序可以幫助您根據選定的列快速將數據分為多個工作表,如Excel中顯示的屏幕截圖所示。  點選取得全功能 30 天免費試用!
doc分割資料2
 
Kutools for Excel:擁有300多個便捷的Excel加載項,可以在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 (63)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Thanks, this was awesome. There are dozens of pages on the internet talking about how to do this. You guys are the only ones that got the VBA code right. Many thanks. I had a big monster workbook with about 100 tabs, all relatively small, and the VBA macro knocked it out in about five minutes. Thank God for smart guys like you. :)
Rated 5 out of 5
This comment was minimized by the moderator on the site
This has been extremely helpful, my job was doing some data management manually and this helped me automate it. I do have a question though, as the code is a bit over my head to figure out on my own.

What would I need to change to make it so that it always saves as a CSV file instead of an excel file? I know it'll be part of the IF VAL THEN CASES but I don't follow the formatting of that area.

Thank you,
Matt
This comment was minimized by the moderator on the site
Hi, Matt, I am glad that this article can help you. If you want to save sheets as new CSV files, this article https://www.extendoffice.com/documents/excel/5537-excel-batch-convert-to-csv.html lists the methods on exporting sheets as separated CSV files, hope it can do you a favor.
This comment was minimized by the moderator on the site
I have been using this VBA Code for some time and it worked like a charm until I changed computers. I have the same version of excel but now I am getting a Run Time Error "76" Path Not found. Any ideas what could be causing this? It looks like it is hanging up at MkDir. Any help you can provide is appreciated.
This comment was minimized by the moderator on the site
Hi, can I ask which office version you use?
This comment was minimized by the moderator on the site
I'm having this issue as well. I ran it once a month ago just fine and this came up just now.
This comment was minimized by the moderator on the site
You are amazing! Thank you so very much!
This comment was minimized by the moderator on the site
Thank you so much ! great and useful.
This comment was minimized by the moderator on the site
For Each xWs In xWb.Worksheets
How to do export only selected / grouped sheets to separate excel sheets by using this code.?
This comment was minimized by the moderator on the site
Hi there,

Keep getting a pop up that says 'compile error, invalid outside procedure' when i try and run the code. Any thoughts? Thanks for all your help.
This comment was minimized by the moderator on the site
Hi, Issybeee, I have update the VBA code in the tutorial, you can try the new one again.
This comment was minimized by the moderator on the site
For those of you who save macros in your "Personal.XLSB" or XLSTART (I see more questions below related to this), change the line

Set xWb = Application.ThisWorkbook to

Set xWB = ActiveWorkbook

That will make the macro run from the Active Workbook instead and save in a subfolder to that.
This comment was minimized by the moderator on the site
With the first method, if I hit F5, it opens a pop up window with the function "Go to". My excel is in spanish, im not sure if that is a factor. Any idea on how to fix it?
This comment was minimized by the moderator on the site
You can directly click the Run button of the Microsoft Visual Basic for Applications window.
This comment was minimized by the moderator on the site
Un aporte realmente útil. He probado el módulo con código VBA y funciona a la perfección. Muchas gracias, me has salvado una tarea que me hubiera llevado mucho tiempo con el mover y copiar.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations