At the end of every month, the Boston, Chicago, and Dallas offices each send in a report workbook with the same layout: a Sales sheet, an Expenses sheet, and a Report sheet. Putting them into one workbook by hand means opening each file, right-clicking each tab, and using Move or Copy. Excel then names the second Sales sheet “Sales (2)” and the third “Sales (3)”, so you can no longer tell which office is which. Any formula that reads the tax rate from another sheet turns into a link to the office's original file.
So I added a Combine tab to the PowerShell tool I wrote for splitting sheets into separate files. You list the workbooks, click one button, and every sheet ends up in a single workbook, named like “Boston_Oct_Sales”. Formulas that point to other sheets in the same workbook stay formulas, and no links to the original files are left behind. It drives the Excel already installed on the PC, so it needs no add-in, no macro, and no upload to an online merger.

Two different meanings of “combine workbooks”
When people say they want to merge Excel files, they usually mean one of two things.
| Goal | Example | Best fit |
|---|---|---|
| Collect whole sheets into one workbook | Hand your manager one file that holds every office's report, formatted exactly as sent | This tool, or Move or Copy |
| Stack rows from many files into one table | Pull every office's sales lines into one table for a PivotTable | Power Query (Get Data, From Folder) |
This post covers the first case. Sheets are copied with their formatting, charts, and print settings, which suits reports that people read. If you need one long table to analyze, Power Query, which is built into Excel, is the better tool.
Isn't Move or Copy good enough?
For two workbooks whose sheet names do not clash, yes. Under the hood the tool uses the same copy feature (Sheets.Copy). It starts to pay off when:
- you have 10 or 20 workbooks (pick the folder and click once)
- every file has the same sheet names (sheets are named Workbook_Sheet instead of “Sales (2)”)
- sheets in one file refer to each other (all sheets from a workbook are copied together, so =Sales!B8 on the Report sheet keeps working)
- formulas read from a hidden settings sheet you do not copy (they become values, so no link to the source file remains)
- the files use an older or custom theme (the first workbook's theme colors are copied so chart colors do not change)
What the combined workbook looks like
I tested with three office workbooks. Each has Sales, Expenses, and Report sheets, plus a hidden Settings sheet that holds the tax rate.

On the Sales sheet, “Incl. tax” in column C is =ROUND(B4*(1+TaxRate),0), where TaxRate is a defined name on the hidden Settings sheet. The Report sheet pulls the sales total with =Sales!B8. (My Office is the Japanese edition, so the Excel ribbon in the screenshots is in Japanese.)


I added the three workbooks and clicked Combine. The result was Combined.xlsx with nine sheets, each named after its source workbook.


Here is how the combined workbook compared with the originals.
| Item | In the combined workbook |
|---|---|
| Fill colors, borders, fonts, number formats, column widths | Unchanged |
| Chart | Unchanged, except that the title got larger. Its data now points to the sheet in the combined workbook |
| Theme colors (chart bar colors and so on) | Copied from the first workbook |
| Formulas inside one sheet (=SUM(B4:B7)) | Still formulas |
| Formulas that point to another copied sheet (=Sales!B8) | Still formulas, updated to the new sheet name |
| Formulas that point to a sheet not copied (the TaxRate formula) | Turned into values (759). The defined name that points to the source file is removed |
| Hidden sheets | Not copied (the log says SKIP) |
Two ways to name the sheets
| Option | Chicago_Oct's Sales sheet becomes | Use it when |
|---|---|---|
| Workbook_Sheet (just workbook if 1 sheet) | Chicago_Oct_Sales | every file has the same layout (the default) |
| Original name (adds (2) if taken) | Sales (2) | each file has its own sheet names |
A workbook with a single sheet gets just the workbook name, so Sheet1 in Boston.xlsx becomes “Boston”. Characters that sheet names cannot contain become “_”, and names are cut at Excel's 31-character limit.

Keeping formulas makes every office use Boston's tax rate
For formulas that point to sheets you do not copy, you can choose “Turn into values (recommended)” or “Keep formulas”. With Keep formulas, C4 stayed =ROUND(B4*(1+TaxRate),0).

Then I checked the defined names. There was only one TaxRate, and it pointed to ='D:\…\merge\[Boston_Oct.xlsx]Settings'!$B$1. A workbook can hold only one name called TaxRate, so the Chicago and Dallas sheets were also calculating with Boston's tax rate. All three files use 10% in my test, so the numbers matched. If each office had its own rate, combining alone would change their numbers, and moving Boston's file would break the link. Unless you have a reason to keep them, turn those formulas into values.
Putting split workbooks back together
On the Split tab, “Send split files to Combine” puts the workbooks you just split onto the Combine tab's list. This is for the round trip. You split a report, send each office its file, and combine the corrected files when they come back. Each split workbook has one sheet, so the sheets get their original names back (Boston, Chicago, and so on).

Formulas that were turned into values during the split stay values. If you need the original formulas back, keep the original workbook and paste the updated numbers into it instead.
The PowerShell tool for splitting and combining
This is the same tool as in the post on splitting sheets. Open PowerShell (5.1 or 7), paste the whole script, and press Enter. 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 Combine tab
| Setting | What it does |
|---|---|
| Workbooks | Add... picks one or more files. Folder... adds every .xlsx, .xlsm, .xls, and .xlsb file in a folder in name order, skipping “~$” temporary files. Sheets are combined in this order |
| Up, Down, Remove | Reorder the selected workbooks or take them off the list |
| Sheet names | Workbook_Sheet (just workbook if 1 sheet) or Original name |
| Formulas that point to sheets not copied | Turn into values (recommended) or Keep formulas |
| Save as | If it is empty when you add workbooks, it becomes Combined.xlsx in the first workbook's folder. A previous output file on the list is skipped, not combined into itself |
| Overwrite a file with the same name | When off, nothing happens if the file already exists |
Each workbook is opened read-only and closed without saving, so the source files never change. Output is always .xlsx, so macros from .xlsm files are not carried over. A password-protected workbook is not opened. It shows up as FAILED in the log.
Trying it out
I picked the folder with the three office workbooks using Folder... and clicked Combine. The nine-sheet Combined.xlsx was ready in about 5 seconds with PowerShell 5.1, or about 9 seconds with PowerShell 7 (the first screenshot). The three hidden Settings sheets were skipped, and the output folder opened when it finished.
Clicking Combine again with the same file name did nothing except log a message, because overwrite was off. I also 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 (tested with Excel 2013).
Problems I ran into
“Sales (2)” does not tell you which office it is
My first version defaulted to the original sheet names with (2) and (3) added, the same way Move or Copy names them. When I opened the result, the tabs read Sales, Expenses, Report, Sales (2), and so on, and I had to look at cell A1 to know which office a sheet came from (the “original sheet names” screenshot above). For files that share a layout, the workbook name is what you actually need, so I made Workbook_Sheet the default.
Keep formulas points every sheet at the first workbook
As described above, combining with Keep formulas left one TaxRate name that pointed only to Boston's file. The link list (LinkSources) had a single entry, not one per office. Even when the numbers match, the other offices are being calculated from Boston's file, which is why Turn into values is the default.
Excel can still show up for a moment after the run
When PowerShell drives Excel, EXCEL.EXE can stay in Task Manager after the script ends. The tool 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. In one PowerShell 7 test run, an Excel process was still listed right at the end, but it was gone when I checked again a moment later. Any Excel window you opened yourself is left alone.
Related posts
To go the other way and save each sheet as its own file, see splitting Excel sheets into separate files. To send the combined workbook as a PDF, the tool in batch converting Excel files to PDF with PowerShell handles that.
Summary
- PowerShell can drive the installed Excel to collect the sheets from several workbooks into one
- Sheets are named Workbook_Sheet. Formulas between sheets of the same workbook keep working, and formulas that point to sheets left behind become values
- The same tool splits a workbook into files and can put those files back together


Comments