How to Split Excel workbook into separate Files

This post will guide you how to split a large workbook to separate files and each worksheet should be saved as a single file. How do I split the whole workbook into several excel worksheets or single excel file.

Assuming that you need to split your workbook that contains lots of worksheets into multiple single Excel file and its extension name is CSV.

The simplest way is to copy each worksheet to a single excel workbook or file by manually. So you can select one worksheet that you want to save as a single excel file, then create a new workbook, paste it in the new workbook. Then save it.

If you have hundreds of worksheet in your workbook, then it will be time-consuming and tedious. So do we have a quick way to split workbook to separate excel file? Of course yes, the below will describe one way to split your workbook with VBA code.

1. Split Excel workbook into separate files with VBA code

Let’s see the following steps:

If you want to quickly split a large workbook into several single excel file for each worksheet, then you can write a new Excel VBA macro code to achieve the result. And the below VBA code will save the separated excel file at the directory same as with the master workbook.

1# click on “Visual Basic” command under DEVELOPER Tab.

Get the position of the nth using excel vba1

2# then the “Visual Basic Editor” window will appear.

3# click “Insert” ->”Module” to create a new module

convert column number to letter3

4# paste the below VBA code into the code window. Then clicking “Save” button.

Sub SaveSheetsAsSeparateFiles()
    Dim ws As Worksheet
    Dim savePath As String
    ' Prompt the user to select a folder to save the new files
    savePath = BrowseForFolder("Select a folder to save the files:")
    ' Check if a folder path was returned
    If savePath = "" Then
        MsgBox "No folder was selected.", vbExclamation, "Operation cancelled"
        Exit Sub
    End If
    ' Loop through each sheet in the workbook
    For Each ws In ThisWorkbook.Worksheets
        ' Save the sheet as a new Excel file
        ws.SaveAs Filename:=savePath & "\" & ws.Name & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    Next ws
    ' Inform the user that the process is complete
    MsgBox "All sheets have been saved as separate files.", vbInformation, "Process Complete"
End Sub

Function BrowseForFolder(prompt As String) As String
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
        .Title = prompt
        .AllowMultiSelect = False
        If .Show = -1 Then
            BrowseForFolder = .SelectedItems(1)
            BrowseForFolder = ""
        End If
    End With
    Set fd = Nothing
End Function

5# back to the current worksheet, then run the above excel macro. Click Run command.

split workbook into separate file2
split workbook into separate file3

2. Video: Split Excel workbook into separate files

 This Excel video tutorial will use VBA Macro to split an Excel workbook into individual files for each sheet.

Leave a Reply