Split Excel Sheets Into Separate Files With PowerShell

Advertisement
ssb-eyecatch-en File Operations
Advertisement

Every month, the sales report has one sheet per branch, and each branch should only receive its own sheet. Doing that by hand means right-clicking each tab, choosing Move or Copy, picking “(new book)”, and saving, over and over. Worse, any formula that pulls a number from another sheet turns into a link to the original file, with the full folder path in it, like ='D:\…\[Sales_report.xlsx]Targets'!B4. Send it outside your team and the recipient sees where you keep your files.

So I wrote a small PowerShell tool that drives the Excel already installed on the PC. You pick a workbook, tick the sheets you want, and it saves each one as its own .xlsx. Formulas that point to other sheets become plain values, so no link or path to the original file is left behind. Formatting, column widths, charts, and print settings stay the same. It needs no add-in, no macro, and no upload to an online converter, which makes it usable on a locked-down work PC.

The same tool also works in the other direction. A second tab combines several workbooks into one, so when the split files come back from the branches, you can put them back together (see combining multiple workbooks into one).

The tool that splits Excel sheets into separate workbooks
Four branch sheets ticked and saved as four workbooks in about 10 seconds

Ways to split Excel sheets into separate files

Excel has no built-in “save each sheet as a file” button. These are the usual options.

Method What you do Where it falls short
Move or Copy to a new book Right-click the tab, choose “(new book)”, tick “Create a copy”, then save Repeated for every sheet. Formulas that point to other sheets become links to the original file
Save a copy and delete the other sheets Save the workbook under a new name and remove every sheet you do not need Formulas that pointed to the deleted sheets turn into #REF!
VBA macro Write a macro that copies and saves each sheet Needs a macro-enabled workbook. Many companies block macros
PowerShell (this tool) Pick the workbook, tick the sheets, click one button Only works on a PC with Excel installed

Isn't Move or Copy good enough?

For three or four sheets with no cross-sheet formulas, yes. The tool uses the same Worksheet.Copy feature that Move or Copy uses. It starts to pay off when:

  • you split 12 monthly sheets or 30 sales reps every month (tick the boxes, click once)
  • targets or unit prices come from another sheet (turn them into values, with no path to the original file)
  • you use defined names such as a tax rate (remove names that still point to the original file)
  • you want consistent file names, either Sheet.xlsx or Workbook_Sheet.xlsx
  • the workbook uses an older or custom theme (copy the theme colors so charts keep their colors)

What the split files look like

The test workbook has Summary, four branch sheets (Boston, Chicago, Dallas, Seattle), and Targets, plus a hidden Settings sheet that holds the tax rate. On each branch sheet, sales are typed in, the target comes from the Targets sheet with =Targets!B4, and “Sales incl. tax” uses a defined name: =ROUND(B4*(1+TaxRate),0). Here is the Boston sheet in the original workbook. (My Office is the Japanese edition, so the Excel ribbon in the screenshots is in Japanese.)

The Boston sheet in the original sales report workbook
Each branch sheet has a table and a chart. C4 is a formula that points to the Targets sheet

With only the four branch sheets ticked, the output folder ends up with four workbooks named after the sheets.

Output folder with four split workbooks
Boston.xlsx, Chicago.xlsx, Dallas.xlsx, and Seattle.xlsx
Boston.xlsx opened in Excel after the split
It looks the same as the original sheet. C4 is now the value 2,300 instead of a formula

I opened each split workbook and checked it against the original sheet.

Item In the split workbook
Fill colors, borders, fonts, number formats Unchanged
Column widths, hidden gridlines Unchanged
Conditional formatting (rate below 100% in red) Unchanged
Chart Unchanged, except that the title got larger in my test. Its data now points to the sheet in the new workbook
Theme colors (chart bar colors and so on) Copied from the original workbook (see “Problems I ran into”)
Print settings (landscape, print area) Unchanged
Formulas inside the same sheet (=B4/C4, =SUM(B4:B9)) Still formulas
Formulas that point to another sheet (=Targets!B4) Turned into values (2,300)
Formulas that use a defined name (=ROUND(B4*(1+TaxRate),0)) Turned into values (2,013). The defined name that points to the original file is removed

Three ways to handle formulas

You choose what happens to formulas that point to other sheets. Here is what C4, D4, and E4 on the Boston sheet became with each option.

Option C4 (=Targets!B4) D4 (=B4/C4) E4 (uses TaxRate)
Turn into values (recommended) 2300 =B4/C4 2013
Turn every formula into a value 2300 0.7956… (shown as 79.6%) 2013
Keep formulas ='D:\…\[Sales_report_H1_2026.xlsx]Targets'!B4 =B4/C4 =ROUND(B4*(1+TaxRate),0)

“Keep formulas” gives you the same result as splitting by hand with Move or Copy. C4 holds the full path of the original file, and the TaxRate name still points there as well.

C4 in Boston.xlsx split with Keep formulas
The formula bar shows the full path of the original file

That is fine if everyone opens the files from the same shared folder as the original. If the files leave your team, the recipient sees your folder names. “Turn every formula into a value” also replaces totals and rates with plain numbers, which suits final figures. If the recipient later edits a sales number, the total will not change.

The PowerShell tool for splitting and combining

Open PowerShell (5.1 or 7), paste the whole script, and press Enter. The window opens with two tabs, “Split sheets into workbooks” and “Combine workbooks into one”. This post uses the first one. You do not need to run it as administrator. If you save it as a .ps1 file, save it as UTF-8 with BOM.

# Split Excel sheets into separate workbooks / combine several workbooks into one (PowerShell 5.1 / 7, on a PC with Excel installed)
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()

function Add-Ctl($parent, $ctl, $x, $y, $w, $h) {
    $ctl.Location = New-Object System.Drawing.Point($x, $y)
    $ctl.Size = New-Object System.Drawing.Size($w, $h)
    $parent.Controls.Add($ctl)
    return $ctl
}
function Write-Log($msg) {
    $txtLog.AppendText($msg + "`r`n")
    [System.Windows.Forms.Application]::DoEvents()
}
function Release($obj) {
    if ($null -ne $obj) { [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($obj) }
}

# Start Excel in the background, run $work, then always shut Excel down
function Use-Excel([scriptblock]$work) {
    $before = @(Get-Process EXCEL -ErrorAction SilentlyContinue).Id
    $excel = New-Object -ComObject Excel.Application
    $mine = @(Get-Process EXCEL -ErrorAction SilentlyContinue | Where-Object { $before -notcontains $_.Id })
    $excel.Visible = $false
    $excel.DisplayAlerts = $false
    $excel.AutomationSecurity = 3            # never run macros (msoAutomationSecurityForceDisable)
    $books = $excel.Workbooks
    try {
        & $work $books
    } finally {
        Release $books
        $excel.Quit()
        Release $excel
        [GC]::Collect(); [GC]::WaitForPendingFinalizers()
        # If the Excel this tool started is still running after 5 seconds, end it (Excel you opened yourself is left alone)
        foreach ($p in $mine) {
            if (-not $p.WaitForExit(5000)) { Stop-Process -Id $p.Id -Force; Write-Log "Ended a leftover background Excel" }
        }
    }
}
# 0 = do not update links, $true = read-only, "" = fail instead of asking for a password
function Open-Book($books, $path) { return $books.Open($path, 0, $true, [Type]::Missing, "") }

# A new workbook starts with the default theme, so chart colors etc. can change -> copy the theme colors from the source
function Copy-ThemeColors($from, $to) {
    $s = $from.Theme.ThemeColorScheme; $d = $to.Theme.ThemeColorScheme
    for ($i = 1; $i -le 12; $i++) { $a = $s.Colors($i); $b = $d.Colors($i); $b.RGB = $a.RGB; Release $a; Release $b }
    Release $s; Release $d
}
# Turn formulas that point to other workbooks into values, then delete defined names (e.g. TaxRate) that point to other workbooks. Returns whether any link was broken
function Remove-Links($wb) {
    $links = $wb.LinkSources(1)                 # 1 = xlExcelLinks
    if ($null -ne $links) { foreach ($l in @($links)) { $wb.BreakLink($l, 1) } }
    foreach ($n in @($wb.Names)) {
        if ($n.RefersTo -like "*[[]*]*") { $n.Delete() }
        Release $n
    }
    return ($null -ne $links)
}
# Replace characters not allowed in sheet names with "_", cut to 31 characters, then add (2), (3)... if the name is taken
function Get-SheetName($wanted, $used) {
    $n = ($wanted -replace '[\\/:*?\[\]]', "_").Trim("'")
    if ($n.Length -gt 31) { $n = $n.Remove(31) }
    $try = $n; $i = 2
    while ($used.Contains($try.ToLower())) {
        $tail = " ($i)"
        $try = $(if ($n.Length + $tail.Length -gt 31) { $n.Remove(31 - $tail.Length) } else { $n }) + $tail
        $i++
    }
    [void]$used.Add($try.ToLower())
    return $try
}

# ---------- Split ----------
function Load-Sheets {
    $lstSheets.Items.Clear()
    $path = $txtBook.Text.Trim()
    if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { Write-Log "Workbook not found"; return }
    $script:hidden = 0
    Use-Excel {
        param($books)
        $book = Open-Book $books $path
        $sheets = $book.Worksheets
        foreach ($ws in @($sheets)) {
            if ($ws.Visible -eq -1) { [void]$lstSheets.Items.Add($ws.Name, $true) } else { $script:hidden++ }
            Release $ws
        }
        Release $sheets; $book.Close($false); Release $book
    }
    $msg = "Loaded {0} sheet(s)" -f $lstSheets.Items.Count
    if ($script:hidden -gt 0) { $msg += " ({0} hidden sheet(s) not listed)" -f $script:hidden }
    Write-Log $msg
    if ($txtDest.Text.Trim() -eq "") {
        $txtDest.Text = Join-Path (Split-Path $path -Parent) ([IO.Path]::GetFileNameWithoutExtension($path) + "_sheets")
    }
}

function Split-Book {
    $names = @($lstSheets.CheckedItems)
    if ($names.Count -eq 0) { Write-Log "Check the sheets you want to split out"; return }
    $path = $txtBook.Text.Trim()
    $dest = $txtDest.Text.Trim().TrimEnd("\")
    if ($dest -eq "") { Write-Log "Enter an output folder"; return }
    New-Item -ItemType Directory -Path $dest -Force | Out-Null
    $base = [IO.Path]::GetFileNameWithoutExtension($path)
    Write-Log ("Splitting {0} sheet(s) into separate workbooks -> {1}" -f $names.Count, $dest)
    $script:ok = 0; $script:ng = 0
    Use-Excel {
        param($books)
        $book = Open-Book $books $path
        $sheets = $book.Worksheets
        foreach ($name in $names) {
            $file = ($name -replace '[\\/:*?"<>|]', "_") + ".xlsx"
            if ($radName2.Checked) { $file = $base + "_" + $file }
            $out = Join-Path $dest $file
            if ((Test-Path -LiteralPath $out) -and -not $chkOver.Checked) { Write-Log "SKIP  $file (a file with that name already exists)"; continue }
            $ws = $null; $nb = $null; $nws = $null; $used = $null
            try {
                $ws = $sheets.Item($name)
                $ws.Copy()                                  # no arguments = copy into a new workbook
                $nb = $books.Item($books.Count)
                Copy-ThemeColors $book $nb
                $note = ""
                if (-not $radKeep.Checked) {
                    # Formulas that point to other sheets become links to the original workbook after the copy -> turn them into values
                    if (Remove-Links $nb) { $note = " (formulas pointing to other sheets were turned into values)" }
                }
                if ($radValue.Checked) {
                    $nws = $nb.Worksheets.Item(1)
                    $used = $nws.UsedRange
                    $used.Value2 = $used.Value2             # replace every formula with its result
                    $note = " (all formulas were turned into values)"
                }
                $nb.SaveAs($out, 51)                        # 51 = .xlsx
                Write-Log "OK  $name → $file$note"
                $script:ok++
            } catch {
                Write-Log "FAILED  ${name}: $($_.Exception.Message)"
                $script:ng++
            } finally {
                Release $used; Release $nws
                if ($null -ne $nb) { $nb.Close($false); Release $nb }
                Release $ws
            }
        }
        Release $sheets; $book.Close($false); Release $book
    }
    Write-Log ("Done ({0} workbook(s) saved, {1} failed)" -f $script:ok, $script:ng)
    if ($script:ok -gt 0) { Invoke-Item -LiteralPath $dest }
}

# ---------- Combine ----------
function Add-Files($paths) {
    foreach ($p in $paths) {
        $name = [IO.Path]::GetFileName($p)
        if ([IO.Path]::GetExtension($p).ToLower() -notin ".xlsx", ".xlsm", ".xls", ".xlsb" -or $name -like '~$*') { continue }
        if (-not $lstFiles.Items.Contains($p)) { [void]$lstFiles.Items.Add($p) }
    }
    if ($txtOut.Text.Trim() -eq "" -and $lstFiles.Items.Count -gt 0) { $txtOut.Text = Join-Path (Split-Path $lstFiles.Items[0] -Parent) "Combined.xlsx" }
}

function Merge-Books {
    $files = @($lstFiles.Items)
    if ($files.Count -eq 0) { Write-Log "Add the workbooks you want to combine"; return }
    $out = $txtOut.Text.Trim()
    if ($out -eq "") { Write-Log "Enter the file to save"; return }
    if (-not $out.EndsWith(".xlsx", [StringComparison]::OrdinalIgnoreCase)) { $out += ".xlsx" }
    if ((Test-Path -LiteralPath $out) -and -not $chkOver2.Checked) { Write-Log "A file with that name already exists (tick Overwrite to replace it)"; return }
    New-Item -ItemType Directory -Path (Split-Path $out -Parent) -Force | Out-Null
    Write-Log ("Combining {0} workbook(s) into one -> {1}" -f $files.Count, $out)
    $script:ok = 0; $script:ng = 0
    Use-Excel {
        param($books)
        $dest = $books.Add()
        $blank = $dest.Worksheets.Item(1)           # the sheet a new workbook starts with (deleted at the end)
        $used = New-Object System.Collections.Generic.HashSet[string]
        $themeDone = $false
        try {
            foreach ($f in $files) {
                if ([IO.Path]::GetFullPath($f) -eq [IO.Path]::GetFullPath($out)) { Write-Log "SKIP  $([IO.Path]::GetFileName($f)) (same as the output file)"; continue }   # Do not merge the previous output into itself
                $src = $null; $sheets = $null
                try {
                    $src = Open-Book $books $f
                    if (-not $themeDone) { Copy-ThemeColors $src $dest; $themeDone = $true }   # use the colors of the first workbook
                    $base = [IO.Path]::GetFileNameWithoutExtension($f)
                    $sheets = $src.Worksheets
                    $names = @()
                    foreach ($ws in @($sheets)) {
                        if ($ws.Visible -eq -1) { $names += $ws.Name } else { Write-Log "SKIP  $base [$($ws.Name)] (hidden sheet)" }
                        Release $ws
                    }
                    if ($names.Count -eq 0) { continue }
                    # Copy all sheets of one workbook together, so formulas between those sheets stay formulas
                    $group = $sheets.Item([object[]]$names)
                    $start = $dest.Worksheets.Count
                    $last = $dest.Worksheets.Item($start)
                    $group.Copy([Type]::Missing, $last)     # copy to the end of the combined workbook
                    Release $last; Release $group
                    for ($k = 0; $k -lt $names.Count; $k++) {
                        $added = $dest.Worksheets.Item($start + 1 + $k)
                        $wanted = if ($radSheet2.Checked) { $names[$k] } elseif ($names.Count -eq 1) { $base } else { $base + "_" + $names[$k] }   # A workbook with only one sheet: use the workbook name
                        $newName = Get-SheetName $wanted $used
                        if ($added.Name -ne $newName) { $added.Name = $newName }
                        Write-Log "OK  $base [$($names[$k])] → [$newName]"
                        $script:ok++
                        Release $added
                    }
                } catch {
                    Write-Log "FAILED  ${f}: $($_.Exception.Message)"
                    $script:ng++
                } finally {
                    Release $sheets
                    if ($null -ne $src) { $src.Close($false); Release $src }
                }
            }
            if ($script:ok -gt 0) {
                $blank.Delete()
                # Formulas that point to sheets that were not copied (hidden ones, for example) become links to the source workbook -> turn them into values
                if ($radMValue.Checked -and (Remove-Links $dest)) { Write-Log "Formulas that pointed to the source workbooks were turned into values" }
                $first = $dest.Worksheets.Item(1); [void]$first.Activate(); Release $first
                $dest.SaveAs($out, 51)                  # 51 = .xlsx
            }
        } finally {
            Release $blank
            $dest.Close($false); Release $dest
        }
    }
    Write-Log ("Done ({0} sheet(s) combined, {1} failed)" -f $script:ok, $script:ng)
    if ($script:ok -gt 0) { Invoke-Item -LiteralPath (Split-Path $out -Parent) }
}

# ---------- Window ----------
$form = New-Object System.Windows.Forms.Form
$form.Text = "Split or combine Excel sheets"
$form.Size = New-Object System.Drawing.Size(820, 660)
$form.StartPosition = "CenterScreen"
$form.Font = New-Object System.Drawing.Font("Segoe UI", 9)
$tabs = Add-Ctl $form (New-Object System.Windows.Forms.TabControl) 8 8 790 390
$tab1 = New-Object System.Windows.Forms.TabPage; $tab1.Text = "Split sheets into workbooks"
$tab2 = New-Object System.Windows.Forms.TabPage; $tab2.Text = "Combine workbooks into one"
$tabs.TabPages.Add($tab1); $tabs.TabPages.Add($tab2)

# Split tab
$lbl = Add-Ctl $tab1 (New-Object System.Windows.Forms.Label) 8 15 110 20; $lbl.Text = "Workbook"
$txtBook = Add-Ctl $tab1 (New-Object System.Windows.Forms.TextBox) 120 12 470 23
$btnPick = Add-Ctl $tab1 (New-Object System.Windows.Forms.Button) 598 11 80 25; $btnPick.Text = "Browse..."
$btnLoad = Add-Ctl $tab1 (New-Object System.Windows.Forms.Button) 686 11 80 25; $btnLoad.Text = "Load"
$btnPick.Add_Click({
    $dlg = New-Object System.Windows.Forms.OpenFileDialog
    $dlg.Filter = "Excel workbooks|*.xlsx;*.xlsm;*.xls;*.xlsb"
    if ($dlg.ShowDialog() -eq "OK") { $txtBook.Text = $dlg.FileName; $txtDest.Text = ""; Load-Sheets }
})
$btnLoad.Add_Click({ $txtDest.Text = ""; Load-Sheets })
$lbl = Add-Ctl $tab1 (New-Object System.Windows.Forms.Label) 8 45 110 20; $lbl.Text = "Sheets to split"
$lstSheets = Add-Ctl $tab1 (New-Object System.Windows.Forms.CheckedListBox) 120 42 300 170
$lstSheets.CheckOnClick = $true
$grp = Add-Ctl $tab1 (New-Object System.Windows.Forms.GroupBox) 432 38 335 120; $grp.Text = "Formulas that point to other sheets"
$radLink = New-Object System.Windows.Forms.RadioButton; $radLink.Text = "Turn into values (recommended)"; $radLink.Checked = $true
$radValue = New-Object System.Windows.Forms.RadioButton; $radValue.Text = "Turn every formula into a value"
$radKeep = New-Object System.Windows.Forms.RadioButton; $radKeep.Text = "Keep formulas (links to the original remain)"
$y = 22
foreach ($r in $radLink, $radValue, $radKeep) { [void](Add-Ctl $grp $r 12 $y 315 24); $y += 30 }
$grp2 = Add-Ctl $tab1 (New-Object System.Windows.Forms.GroupBox) 432 162 335 50; $grp2.Text = "File name"
$radName1 = Add-Ctl $grp2 (New-Object System.Windows.Forms.RadioButton) 12 20 130 24; $radName1.Text = "Sheet.xlsx"; $radName1.Checked = $true
$radName2 = Add-Ctl $grp2 (New-Object System.Windows.Forms.RadioButton) 150 20 180 24; $radName2.Text = "Workbook_Sheet.xlsx"
$lbl = Add-Ctl $tab1 (New-Object System.Windows.Forms.Label) 8 228 110 20; $lbl.Text = "Output folder"
$txtDest = Add-Ctl $tab1 (New-Object System.Windows.Forms.TextBox) 120 225 558 23
$btn = Add-Ctl $tab1 (New-Object System.Windows.Forms.Button) 686 224 80 25; $btn.Text = "Browse..."
$btn.Add_Click({
    $dlg = New-Object System.Windows.Forms.FolderBrowserDialog
    if (Test-Path -LiteralPath $txtDest.Text) { $dlg.SelectedPath = $txtDest.Text }
    if ($dlg.ShowDialog() -eq "OK") { $txtDest.Text = $dlg.SelectedPath }
})
$chkOver = Add-Ctl $tab1 (New-Object System.Windows.Forms.CheckBox) 120 253 400 22; $chkOver.Text = "Overwrite files with the same name"
$btnSplit = Add-Ctl $tab1 (New-Object System.Windows.Forms.Button) 8 290 200 34; $btnSplit.Text = "Split sheets"

# Combine tab
$lbl = Add-Ctl $tab2 (New-Object System.Windows.Forms.Label) 8 15 110 20; $lbl.Text = "Workbooks"
$lstFiles = Add-Ctl $tab2 (New-Object System.Windows.Forms.ListBox) 120 12 558 160
$lstFiles.SelectionMode = "MultiExtended"; $lstFiles.HorizontalScrollbar = $true
$btnAdd = Add-Ctl $tab2 (New-Object System.Windows.Forms.Button) 686 11 80 25; $btnAdd.Text = "Add..."
$btnDir = Add-Ctl $tab2 (New-Object System.Windows.Forms.Button) 686 41 80 25; $btnDir.Text = "Folder..."
$btnUp = Add-Ctl $tab2 (New-Object System.Windows.Forms.Button) 686 81 80 25; $btnUp.Text = "Up"
$btnDown = Add-Ctl $tab2 (New-Object System.Windows.Forms.Button) 686 111 80 25; $btnDown.Text = "Down"
$btnDel = Add-Ctl $tab2 (New-Object System.Windows.Forms.Button) 686 146 80 25; $btnDel.Text = "Remove"
$btnAdd.Add_Click({
    $dlg = New-Object System.Windows.Forms.OpenFileDialog
    $dlg.Filter = "Excel workbooks|*.xlsx;*.xlsm;*.xls;*.xlsb"; $dlg.Multiselect = $true
    if ($dlg.ShowDialog() -eq "OK") { Add-Files ($dlg.FileNames | Sort-Object) }
})
$btnDir.Add_Click({
    $dlg = New-Object System.Windows.Forms.FolderBrowserDialog
    if ($dlg.ShowDialog() -eq "OK") {
        Add-Files (Get-ChildItem -LiteralPath $dlg.SelectedPath -File | Sort-Object Name | ForEach-Object { $_.FullName })
    }
})
$btnUp.Add_Click({
    $i = $lstFiles.SelectedIndex
    if ($i -gt 0) { $v = $lstFiles.Items[$i]; $lstFiles.Items.RemoveAt($i); $lstFiles.Items.Insert($i - 1, $v); $lstFiles.ClearSelected(); $lstFiles.SelectedIndex = $i - 1 }
})
$btnDown.Add_Click({
    $i = $lstFiles.SelectedIndex
    if ($i -ge 0 -and $i -lt $lstFiles.Items.Count - 1) { $v = $lstFiles.Items[$i]; $lstFiles.Items.RemoveAt($i); $lstFiles.Items.Insert($i + 1, $v); $lstFiles.ClearSelected(); $lstFiles.SelectedIndex = $i + 1 }
})
$btnDel.Add_Click({ foreach ($v in @($lstFiles.SelectedItems)) { $lstFiles.Items.Remove($v) } })
$grp3 = Add-Ctl $tab2 (New-Object System.Windows.Forms.GroupBox) 120 180 300 80; $grp3.Text = "Sheet names"
$radSheet1 = Add-Ctl $grp3 (New-Object System.Windows.Forms.RadioButton) 12 20 280 24; $radSheet1.Text = "Workbook_Sheet (just workbook if 1 sheet)"; $radSheet1.Checked = $true
$radSheet2 = Add-Ctl $grp3 (New-Object System.Windows.Forms.RadioButton) 12 48 280 24; $radSheet2.Text = "Original name (adds (2) if taken)"
$grp4 = Add-Ctl $tab2 (New-Object System.Windows.Forms.GroupBox) 432 180 335 80; $grp4.Text = "Formulas that point to sheets not copied"
$radMValue = Add-Ctl $grp4 (New-Object System.Windows.Forms.RadioButton) 12 20 315 24; $radMValue.Text = "Turn into values (recommended)"; $radMValue.Checked = $true
$radMKeep = Add-Ctl $grp4 (New-Object System.Windows.Forms.RadioButton) 12 48 315 24; $radMKeep.Text = "Keep formulas (links to the source remain)"
$lbl = Add-Ctl $tab2 (New-Object System.Windows.Forms.Label) 8 273 110 20; $lbl.Text = "Save as"
$txtOut = Add-Ctl $tab2 (New-Object System.Windows.Forms.TextBox) 120 270 558 23
$btn = Add-Ctl $tab2 (New-Object System.Windows.Forms.Button) 686 269 80 25; $btn.Text = "Browse..."
$btn.Add_Click({
    $dlg = New-Object System.Windows.Forms.SaveFileDialog
    $dlg.Filter = "Excel workbook|*.xlsx"; $dlg.FileName = "Combined.xlsx"
    if ($dlg.ShowDialog() -eq "OK") { $txtOut.Text = $dlg.FileName }
})
$chkOver2 = Add-Ctl $tab2 (New-Object System.Windows.Forms.CheckBox) 120 298 400 22; $chkOver2.Text = "Overwrite a file with the same name"
$btnMerge = Add-Ctl $tab2 (New-Object System.Windows.Forms.Button) 8 290 200 34; $btnMerge.Text = "Combine"
$btnMerge.Top = 325

# Send the split workbooks straight to the Combine tab
$btnSend = Add-Ctl $tab1 (New-Object System.Windows.Forms.Button) 220 290 260 34; $btnSend.Text = "Send split files to Combine"
$btnSend.Add_Click({
    $d = $txtDest.Text.Trim()
    if (-not (Test-Path -LiteralPath $d)) { Write-Log "The output folder does not exist yet"; return }
    $lstFiles.Items.Clear()
    Add-Files (Get-ChildItem -LiteralPath $d -File | Sort-Object Name | ForEach-Object { $_.FullName })
    $txtOut.Text = Join-Path $d "Combined.xlsx"
    $tabs.SelectedTab = $tab2
})

$txtLog = Add-Ctl $form (New-Object System.Windows.Forms.TextBox) 8 406 790 200
$txtLog.Multiline = $true; $txtLog.ScrollBars = "Vertical"; $txtLog.ReadOnly = $true

foreach ($b in $btnSplit, $btnMerge) {
    $b.Add_Click({
        $btnSplit.Enabled = $false; $btnMerge.Enabled = $false
        try { if ($tabs.SelectedTab -eq $tab1) { Split-Book } else { Merge-Books } } catch { Write-Log "Stopped: $($_.Exception.Message)" }
        $btnSplit.Enabled = $true; $btnMerge.Enabled = $true
    })
}
[void]$form.ShowDialog()

Feel free to use and modify the script.

Settings on the Split tab

Setting What it does
Workbook Pick a file with Browse... and the sheet list loads. If you type the path yourself, click Load
Sheets to split Every sheet is ticked at first. Untick the ones you do not want (Summary, for example). Hidden sheets are not listed
Formulas that point to other sheets Turn into values, turn every formula into a value, or keep formulas (see the table above)
File name Sheet.xlsx or Workbook_Sheet.xlsx. Characters that are not allowed in file names become “_”
Output folder Defaults to “WorkbookName_sheets” next to the workbook
Overwrite files with the same name When off, existing files are skipped
Send split files to Combine Puts the workbooks in the output folder on the Combine tab's list and switches to that tab (see “Putting the split files back together”)

The workbook is opened read-only and closed without saving, so the original file never changes. Output is always .xlsx, so macros from an .xlsm file are not carried over.

Trying it out

After I picked the sales report with Browse..., six sheets showed up in the list in about 2 seconds (the hidden Settings sheet is not listed). I unticked Summary and Targets, left “Turn into values (recommended)” selected, and clicked Split sheets. Four workbooks were saved in about 10 seconds (the first screenshot), and the output folder opened.

Running it again with the same output folder skipped all four files, because overwrite was off. I logged the Excel processes every 0.3 seconds during the run. A background Excel started only while the tool was working and was gone when it finished. PowerShell 5.1 and 7 gave the same results (tested with Excel 2013).

Putting the split files back together

When the branches send their files back, click “Send split files to Combine” and then Combine on the second tab. Each split workbook has a single sheet, so the sheets are named after the workbooks (Boston, Chicago, and so on). In my test the four files were back in one workbook in 5 to 9 seconds. Cells that were turned into values stay values. The details are in combining multiple workbooks into one.

Problems I ran into

Breaking links still left a defined name pointing to the original file

My first version only called BreakLink. The link list in the split workbook was empty, and the tax formula had become a value. When I checked the defined names, though, TaxRate still pointed to ='D:\…\[Sales_report_H1_2026.xlsx]Settings'!$B$1. No formula used it any more, yet the path to the original file was still in the workbook. The tool now deletes any defined name that refers to another workbook after breaking the links.

The chart colors changed in the split workbook

When I opened the first version's output, the table matched but the chart bars had changed from blue and red to light blue and orange. Copying a sheet to a new book creates that book with Excel's default theme, so anything colored by the theme (charts, shapes) can change. My test workbook used the older Office 2007-2010 theme, which made the difference obvious. Cells with an explicit fill color do not change.

Chart colors in the original workbook and in the first version's output
Left: the original workbook. Right: the first version's output, with different bar colors and a larger title

The tool now copies the 12 theme colors from the original workbook to each new one, and the charts keep their colors. Copying the colors added about a second per sheet, so four sheets went from about 4 seconds to about 10. The chart title still comes out larger in the split file, so resize it afterward if that matters.

Making sure Excel does not stay running in the background

When PowerShell drives Excel, EXCEL.EXE can stay in Task Manager after the script ends. The script releases each sheet and workbook with ReleaseComObject, calls Quit, and runs garbage collection. If the Excel it started is still there after 5 seconds, it ends that process only. Any Excel window you opened yourself is left alone.

Related posts

To combine workbooks from several branches into one, see combining multiple workbooks into one. If the sheets should go out as PDFs instead, the tool in batch converting Excel files to PDF with PowerShell has a “one PDF per sheet” option. To put each file into its own branch folder, see creating folders and subfolders from an Excel list.

Summary

  • PowerShell can drive the installed Excel to save each ticked sheet as its own .xlsx
  • Formatting, column widths, charts, theme colors, and print settings carry over. Cross-sheet formulas become values, so no link or path to the original file remains
  • No macros, the original workbook is untouched, and no Excel is left running
  • The same tool can also combine the split files, or any set of workbooks, into one

References

Comments

Copied title and URL