Note: The other languages of the website are Google-translated. Back to English
登入  \/ 
x
or
x
註冊  \/ 
x

or

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

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

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

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

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


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

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

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

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

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

doc導出表2

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

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


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

在Microsoft Excel中,可以通過將工作表複製並粘貼到新工作簿中,將一個工作簿中的工作表保存或拆分為新的Excel文件。 如果要將大工作簿的每個工作表/工作表拆分為單獨的Excel,txt,csv,pdf文件,這似乎很麻煩。 但是隨著 Kutools for Excel拆分工作簿 實用程序,您可以快速處理它。  單擊具有全部功能的 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代碼可能有點複雜。 在這裡您可以使用 拆分工作簿 的效用 Kutools for Excel 以快速輕鬆地導出並保存一個工作簿的每個工作表以分離新工作簿。

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

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

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

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

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


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


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

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

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

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

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


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

假設您有一個工作表,該工作表的數據在A到G列中,推銷員的名字在A列中,並且您需要根據同一工作簿中的A列將這些數據自動拆分為多個工作表,並且每​​個推銷員都會被拆分為一個新的工作表。 Kutools for Excel分割日期 實用程序可以幫助您根據選定的列快速將數據分為多個工作表,如Excel中顯示的屏幕截圖所示。  單擊以獲取功能齊全的 30 天免費試用版!
doc分割資料2
 
Kutools for Excel:擁有300多個便捷的Excel加載項,可以在30天內免費試用。

相關文章:


最佳辦公效率工具

Kutools for Excel 解決了您的大部分問題,並將您的生產力提高了 80%

  • 重用: 快速插入 複雜的公式,圖表 以及您以前使用過的任何東西; 加密單元 帶密碼 創建郵件列表 並發送電子郵件...
  • 超級公式欄 (輕鬆編輯多行文本和公式); 閱讀版式 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不會丟失數據; 拆分單元格內容; 合併重複的行/列...防止細胞重複; 比較範圍...
  • 選擇重複或唯一 行; 選擇空白行 (所有單元格都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇...
  • 確切的副本 多個單元格,無需更改公式參考; 自動創建參考 到多張紙; 插入項目符號,複選框等...
  • 提取文字,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級濾鏡 (將過濾方案保存並應用於其他工作表); 高級排序 按月/週/日,頻率及更多; 特殊過濾器 用粗體,斜體...
  • 結合工作簿和工作表; 根據關鍵列合併表; 將數據分割成多個工作表; 批量轉換xls,xlsx和PDF...
  • 300 多項強大功能。 支持Office / Excel 2007-2019和365。支持所有語言。 在您的企業或組織中輕鬆部署。 完整功能30天免費試用。 60天退款保證。
kte選項卡201905

Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
officetab底部
Say something here...
symbols left.
You are guest
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.
    mbtedrick@aol.com · 1 months ago
    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.
  • To post as a guest, your comment is unpublished.
    Lisa · 2 months ago
    You are amazing! Thank you so very much!
  • To post as a guest, your comment is unpublished.
    Nadine · 7 months ago
    Thank you so much ! great and useful.
  • To post as a guest, your comment is unpublished.
    Sameer Kuppanath · 10 months ago
    For Each xWs In xWb.Worksheets

    How to do export only selected / grouped sheets to separate excel sheets by using this code.?
  • To post as a guest, your comment is unpublished.
    Issybeee · 1 years ago
    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.
    • To post as a guest, your comment is unpublished.
      Sunny · 1 years ago
      Hi, Issybeee, I have update the VBA code in the tutorial, you can try the new one again.
  • To post as a guest, your comment is unpublished.
    Tobias vP · 1 years ago
    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.

  • To post as a guest, your comment is unpublished.
    Diego · 1 years ago
    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?
    • To post as a guest, your comment is unpublished.
      Sunny · 1 years ago
      You can directly click the Run button of the Microsoft Visual Basic for Applications window.
  • To post as a guest, your comment is unpublished.
    kerstin · 2 years ago
    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.
  • To post as a guest, your comment is unpublished.
    SS · 2 years ago
    This is a fantastic piece of work, thanks a lot.
    Do we have any option to select only specific columns in a worksheet to be exported?
    • To post as a guest, your comment is unpublished.
      Sunny · 2 years ago
      Hi, SS, if you want to export a specific selection as a individual file, this article can help you https://www.extendoffice.com/documents/excel/626-excel-save-selection.html
  • To post as a guest, your comment is unpublished.
    JR · 2 years ago
    For anybody who finds the VBA code is not running as expected, try to change Line 9 to "Set xWb = Application.ActiveWorkbook"

    Otherwise, fantastic! Does exactly as described, and runs fairly quickly
  • To post as a guest, your comment is unpublished.
    Vinod Pingale · 2 years ago
    very nice.... Thanks
  • To post as a guest, your comment is unpublished.
    PK · 2 years ago
    How to convert this macro so that I can save it in my personal workbook and can use to where ever I need it.
    • To post as a guest, your comment is unpublished.
      Sunny · 2 years ago
      Click Developer tab > Record Macro > select Personal Macro Workbook, and give the vba a name.
      Then in Microsoft Visual Basic for Applications window, click VBAProject(PERSONA_XLSB) > Modules > double click Module1, paste the code between Sub() and End Sub, save the code.
      When you want to use the code, click Developer > Macro, choose the code you name.
      • To post as a guest, your comment is unpublished.
        brahim · 1 years ago
        xWs.Copy this methode give me an erreor 1004
  • To post as a guest, your comment is unpublished.
    Sergii · 2 years ago
    February 2019 - after some update Excel silently exits macro right after Application.ActiveWorkbook.SaveAs
    It means, that commands Application.ActiveWorkbook.Close does not run and file stays opened... Could it be fixed? This happened all the machines in our office on several workbooks that were using such kind of Macro.
  • To post as a guest, your comment is unpublished.
    Jenne · 3 years ago
    Do you have the formula to make sure that each excel sheet when saved as a new work book is in total format Comma Delimited .CSV
    • To post as a guest, your comment is unpublished.
      Sunny · 2 years ago
      Sorry, I have no idea,neither.
  • To post as a guest, your comment is unpublished.
    Jenne · 3 years ago
    Love this and another info you have on splitting data into each worksheet. However I keep getting an error when trying to upload my single reports into my system

    I needed them as a csv file so just changed the last part of the module to .csv I am wondering if I missed something else that should've been changed.

    Thanks a million
  • To post as a guest, your comment is unpublished.
    Ananda · 3 years ago
    what is the use of Worksheet.Save??
    • To post as a guest, your comment is unpublished.
      erick · 3 years ago
      to save the changes made
    • To post as a guest, your comment is unpublished.
      Sunny · 3 years ago
      What? I do not understand.
  • To post as a guest, your comment is unpublished.
    Eunice · 3 years ago
    Hi Sunny,

    Thank you for sharing this code!

    I keep getting this error "Compile Error: Wrong number of arguments or invalid property assignment" at the "format" portion of the following string:

    DateString = format(Now, "yyyy-mm-dd hh-mm-ss")
  • To post as a guest, your comment is unpublished.
    Borges · 3 years ago
    Hi, I use this VBA code all the time to separate commission statements into individual spreadsheets. Is it possible to add a line to the code so it will automatically email the report to each person using outlook?
    • To post as a guest, your comment is unpublished.
      Sunny · 3 years ago
      Soryy I did not know a code can do that, but you can split the workbook first, then apply Kutools for Excel's Create Mailing List and Send Emails utilities to create a mailing list, and then send the reports as attachments to each person. For more detail, please go to visit this article https://www.extendoffice.com/product/kutools-for-excel/excel-create-mailing-list-and-send-email.html
  • To post as a guest, your comment is unpublished.
    dilshadrana46@gmail.com · 3 years ago
    i cant find enterprise toolbar kindly help me
  • To post as a guest, your comment is unpublished.
    dilshadrana46@gmail.com · 3 years ago
    this code cahnge dates in my sheets
    • To post as a guest, your comment is unpublished.
      Sunny · 3 years ago
      What dates have been changed? The modified dates? The Enterprise tab will be appeared after installing Kutools for Excel.
  • To post as a guest, your comment is unpublished.
    Isuru · 4 years ago
    xWs.Copy line comes up with an error in my case with 2016 "Method 'Copy of object'_Worksheet' failed.
    Please suggest me a correction if possible.
    • To post as a guest, your comment is unpublished.
      Sunny · 4 years ago
      Sorry, I have no idea about your problem.
  • To post as a guest, your comment is unpublished.
    Peggy · 4 years ago
    Hi,


    its totally work with the excel 2010.


    however, after i upgraded to Excel 2016, the code doesn't work.


    would you please advise which part should i be revised?
    • To post as a guest, your comment is unpublished.
      Sunny · 4 years ago
      Excuse me, which method you cannot use in Excel 2016? In my condition, all of the methods above do work in Excel 2016 perfectly
  • To post as a guest, your comment is unpublished.
    Omeir · 4 years ago
    Hi the second method worked great. Thank you. I have one question. This method saves each worksheet as a new workbook based on the name of the sheet. Is there anyway to add to the name, for example sheets have a variable name which is currently being saved. Can I add January 2017 or Feb 2017 to the files saved?
    • To post as a guest, your comment is unpublished.
      Sunny · 4 years ago
      Thanks for your leaving message, you can apply Kutools for Excel's Rename Multiple Worksheets to rename every sheets of the workbook firstly, then use one of above methods to export or save the sheets separately as workbook. If you want to know more detail on Rename Multiple Worksheet utility, please visit this:https://www.extendoffice.com/product/kutools-for-excel/batch-rename-excel-worksheets.html
  • To post as a guest, your comment is unpublished.
    Sarfraz · 4 years ago
    Is there a way to change this macro so I can save it in a file in the XLSTART folder but it will run for the active workbook? Everytime I save it in the XLSTART workbook it fails at the DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")line.

    Thanks!
    Sarfraz
  • To post as a guest, your comment is unpublished.
    Aung · 4 years ago
    This is exactly what I needed! Awesome!
  • To post as a guest, your comment is unpublished.
    Rae · 4 years ago
    Hi. I received an error code that says "Compile error: Invalid outside procedure"...help!
  • To post as a guest, your comment is unpublished.
    DAS · 4 years ago
    Your code worked for me... Thanks much!!!
  • To post as a guest, your comment is unpublished.
    Richard · 4 years ago
    Can we also export ALL (300+) sheets to html,
    this will help me a lot, the export to unified text is already helping but I need them in html, or no table borders for the cell differences
  • To post as a guest, your comment is unpublished.
    Madhav Mehendale · 5 years ago
    Out of the above three methods, I found the first method to be quite good having regard to the fact that I am a beginner & my work is not at all of the same magnitude like professionals. My sincere thanks for explaining the steps in simple and lucid manner.
  • To post as a guest, your comment is unpublished.
    Beth G · 5 years ago
    Run time error Method 'Copy of Object' worksheet' failed
  • To post as a guest, your comment is unpublished.
    Beth G · 5 years ago
    xWs.Copy -it is an error in my part what does it mean?
  • To post as a guest, your comment is unpublished.
    Louise · 5 years ago
    Great article - VBA worked first time - perfect
  • To post as a guest, your comment is unpublished.
    Charlie Clarke · 6 years ago
    Unfortunately the VBA code didn't work for me. I had to debug and the issue is with the line:
    Application.ActiveWorkbook.SaveAs xFile, FileFormat:=FileFormatNum

    Any ideas why it didn't work for me?
  • To post as a guest, your comment is unpublished.
    JoaoM · 6 years ago
    Muy buena la aplicacion.

    Es una pena no existir tambien en Español.

    Gracias
  • To post as a guest, your comment is unpublished.
    AC · 6 years ago
    Very Useful thanks! Loved the VBA Code
  • To post as a guest, your comment is unpublished.
    fauzan · 6 years ago
    thank. terimakasih. ini code yang saya butuhkan
  • To post as a guest, your comment is unpublished.
    farfan · 7 years ago
    The VBA codes works like magic, but is there a way for this to be done using VBScript? I'm going nuts trying to meet the requirement from my supervisor.
  • To post as a guest, your comment is unpublished.
    Chris · 7 years ago
    this code is perfect for what i need,
    but could you show code for the exact same process for one sheet rather than the entire workbook?
  • To post as a guest, your comment is unpublished.
    Sam · 7 years ago
    The code is failing at sh.Copy and I cannot figure out why. Any Ideas?
  • To post as a guest, your comment is unpublished.
    Votefor Pedro · 7 years ago
    Thank you. This is esactly what I needed.
  • To post as a guest, your comment is unpublished.
    Phani · 7 years ago
    Hi All,
    Can someone help me on below.
    I need VBA code that can copy only all visible sheets to new workbook and it should not copy macro code to new workbook, save new workbook on desktop with two different cell values in sheet and sheet name as a file name and close the master workbook without saving.
  • To post as a guest, your comment is unpublished.
    Keith · 7 years ago
    Is there a way to change this macro so I can save it in a file in the XLSTART folder but it will run for the active workbook? Everytime I save it in the XLSTART workbook it fails at the DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")line.

    Thanks!
    Keith
  • To post as a guest, your comment is unpublished.
    Rajesh Jayagopi · 7 years ago
    Thanks a lot. Good Job!.
  • To post as a guest, your comment is unpublished.
    Sean · 7 years ago
    Hello I like the code
    Is it possible to just save the new workbook without the date information That is so when I resave the sheets in the previous workbook I will have the option to overwrite the changes rather than create another dated folder? Also but not so important how could I use another name and destination for the destination folder
    Regards
    Sean
  • To post as a guest, your comment is unpublished.
    Nasser · 7 years ago
    thanks alot, works very well and easy.