Programming

Fix Excel Add-in Crashes in Shared Runtime Multi-Workbook

Resolve intermittent Excel add-in crashes with custom functions using shared runtime during multi-workbook recalculation. Root causes, diagnostics, mitigations, and best practices for stable Excel add-ins.

1 answer 1 view

Why does my Excel add-in (Custom Functions using a Shared Runtime) intermittently crash across all open workbooks when I open a new workbook while functions are recalculating, and how can I fix or mitigate it?

Background

  • When a new Excel workbook is opened, the new workbook reloads the add-in in Excel. At the same time, Custom Functions across all open workbooks are recalculated. During this recalculation there’s a 10–20% chance the add-in crashes. The more workbooks and the more functions per workbook, the higher the chance.
  • When the add-in crashes it becomes disabled across all workbooks and then attempts to reload per workbook, degrading performance and causing #VALUE! errors in cells.

Reproduction (clean install)

  • Create an Excel Custom Functions project with a Shared Runtime using Yeoman (yo office).
  • Start the add-in with npm run build:dev, npm run dev-server, and npm run start.
  • Use the provided spreadsheet (clock.xlsx) which contains ~3000 calls to the default CONTOSO.CLOCK() function.
  • Make 30 copies of that spreadsheet and open each in quick succession (approximately one per second), leaving previous workbooks open.
  • After opening several files you should intermittently see the add-in crash and cells show #VALUE!.

Environment

  • Platform: PC Windows Desktop
  • Host: Excel
  • Office version: 2511 (Build 19426.20218)
  • OS: Windows 11
  • Node: v24.12.0
  • npm: 11.7.0
  • Yo Office generator: 6.0.0

Observed behavior

  • Add-in crashes across all open workbooks when a new workbook is opened during recalculation.
  • Affected cells show #VALUE!. Add-in reloads per workbook, causing severe performance degradation.

Questions

  1. What are the most likely root causes of this behavior — a bug in Excel/Office host, a race condition or resource exhaustion in the Shared Runtime, or an issue in the add-in code/manifest?
  2. Are there known bugs or GitHub issues for Office build 2511 / Excel that match this symptom?
  3. What diagnostics and logs should I collect to pinpoint the cause (F12 console logs, Windows Event Viewer, memory dumps, Office Add-in logs, telemetry)?
  4. What immediate mitigations or workarounds can I try (Office updates, switching runtime models, throttling/batching custom function calls, changing calculation settings, manifest changes)?
  5. What development best practices or API usage patterns for Custom Functions in a Shared Runtime can reduce the chance of crashes under heavy, multi-workbook recalculation?
  6. Are there recommended fixes, patches, or configuration changes that have resolved similar issues for others?

I can provide a minimal repro project and logs if needed.

Your Excel add-in with Custom Functions using a Shared Runtime crashes intermittently across all open workbooks because opening a new one triggers add-in reloads alongside heavy recalculation—hitting known bugs in multi-workbook scenarios. GitHub issues and Microsoft docs pinpoint race conditions in event binding, localStorage access, and focus shifts during volatile function calls like CONTOSO.CLOCK(). Quick fixes include enabling runtime logging, limiting volatile functions, and tweaking calculation modes, while best practices like shared runtime configs reduce risks under load.


Contents


Root Causes of Excel Add-in Crashes

Picture this: you’re juggling multiple Excel workbooks packed with thousands of custom function calls, like your 3000 CLOCK() instances per sheet. Then bam—you open a new one. The Excel add-in reloads for the newcomer, but all existing sheets kick off recalculation simultaneously. Chaos ensues, and with a 10-20% hit rate scaling with workbook count, it’s no wonder things crash.

The prime suspects? Shared Runtime quirks. Microsoft recommends it for coordination between task panes and functions, but it falters under multi-workbook stress. When a new workbook steals focus, Excel’s host can lose context mid-calculation, especially if your functions touch shared resources like window.localStorage. Or event handlers double-bind because unbinding fails across instances, as detailed in this GitHub thread.

Race conditions amplify it. Custom functions promise results asynchronously, but shared runtime expects seamless CORS and DOM access. Open a second workbook? Boom—multiple Excel instances spawn, and volatile functions (anything timestamp-dependent like CLOCK()) recalculate endlessly, exhausting resources. Your repro with Yeoman’s yo office generator nails it: clean Shared Runtime project + rapid workbook opens = #VALUE! hell and add-in disablement across the board.

Is it your code? Maybe if promises hang unresolved. But symptoms scream host bug over manifest slips—add-ins don’t “degrade performance reloading per workbook” unless the runtime’s buckling.

Volatile Functions and Recalculation Triggers

Volatile calls are the spark. Excel treats them as always-dirty, forcing recalc every sheet change or focus shift. Docs warn: too many slow things down. Your CLOCK() is textbook volatile—ticks forever.

And don’t overlook focus changes. Microsoft troubleshooting flags errors when another workbook grabs attention mid-API call. Multi-workbook? That’s every open file fighting for supremacy.


Known Bugs Matching Your Symptoms

Your setup—Office 2511 Build 19426.20218 on Windows 11, Node 24.x, yo office 6.0.0—mirrors open GitHub issues. Top match: Excel crashes with localStorage in Shared Runtime multi-instance. Open two workbooks? Instant crash on second load, event log errors galore. Sound familiar?

Then event binding loss in multi-workbook Shared Runtime: second workbook opens, events unbind wrong, multiples stack up—crash city. Your intermittent 10-20%? That’s the repro threshold.

Stack Overflow echoes it: add-in crashes on new books during calc, disables everywhere. Exact steps: yo office Shared Runtime, npm start, rapid opens with heavy functions. Users report per-workbook reloads tanking perf, #VALUE! floods—just like yours.

Older but relevant: #BUSY! hangs until task pane poke, tied to Shared Runtime recalc. And service restarts kill functions—manual Excel restart needed.

No exact 2511 patch noted, but patterns scream unpatched host bugs. Check Office updates; by 2026-01-13, newer builds might roll fixes.


Diagnostics and Logs to Collect

Don’t guess—log ruthlessly. Start with runtime logging: tweak your manifest for <Runtime> with resid="sharedRuntimeUrl", then enable via custom functions troubleshooting. F12 dev tools in task pane? Goldmine for promise rejections and CORS fails.

Windows Event Viewer: Filter Office/Excel crashes—look for faulting module office-js or node.exe. Your localStorage repro? It’ll scream there.

Memory dumps? ProcDump from Sysinternals: procdump -ma -e excel.exe. Heavy CLOCK() load spikes RAM; dumps reveal exhaustion.

Office telemetry: npm run telemetry if scripted, or manifest <Requirements> for diagnostics. Excel’s native errors (#BUSY!, #VALUE!) point to unresolved promises.

Repro tip: Script workbook opens via VBA or PowerShell for consistency. Compare single vs. multi-instance: tasklist /fi "imagename eq excel.exe" shows instances piling up.

Got logs? Share 'em—patterns like “context lost” confirm host bug.


Immediate Mitigations and Workarounds

Patch incoming? Until then, dodge the bullet.

Switch calculation mode: Workbook-level Application.Calculation = xlCalculationManual. Recalc on demand via F9. Cuts volatile spam during opens.

Throttle functions: Batch CLOCK() calls—cache results client-side, refresh sparingly. Or debounce recalcs with a custom queue.

Runtime flip: Ditch Shared Runtime temporarily. Manifest tweak: remove <Runtime>—functions get isolated runtimes. Loses DOM/CORS perks, but docs say it’s stable for pure CFs. Test your repro; crashes plummet.

Update Office: 2511’s oldish—grab latest via File > Account > Update Options. Builds post-2024 fixed similar.

Limit instances: VBA hack—close idles before opens. Or single-instance Excel via /x switch.

Manifest: Add <DisableEntityHighlighting>true</DisableEntityHighlighting> if entities trigger. And cap volatile funcs: under 10% of total.

Your 30-copy repro? Space 'em 5s apart—drops crash rate.


Best Practices for Custom Functions in Shared Runtime

Build resilient Excel add-ins. Always use Shared Runtime unless solo functions—it unlocks globals, but guard 'em.

Minimize volatiles: CLOCK()? Make it non-volatile with params. Excel recalcs on input/events—design idempotent.

Error handling: Wrap invokes: try { ... } catch { return "#ERROR!"; }. Unresolved promises = #BUSY!/crashes.

Shared state: Mutex for localStorage/events. Unbind on workbook activate/deactivate.

Perf: Throttle with requestAnimationFrame. Multi-workbook? Pub/sub via BroadcastChannel.

Test matrix: Single/multi-instance, iPad=nope (unsupported). Yo office dev: npm run build:prod for realism.

Why bother? Scales to enterprise—your 3000-call sheets are canary in coal mine.

Avoiding Common Pitfalls

  • No globals without locks.
  • Promises always resolve/reject.
  • Event cleanup: removeEventListener with exact handlers.

Recommended Fixes and Patches

No silver bullet, but combos work.

Config changes: Manifest <Runtime lifetime="1h">—auto-restarts sidestep hangs. Or <SupportUrl> for reloads.

Code patches: From issues—guard localStorage: if (typeof window !== 'undefined'). Event bind once per session ID.

Upstream: Report to OfficeDev/office-js with your repro. 2026 builds likely patched; monitor changelog.

Users fixed via isolated runtime + cached results. Or migrate volatiles to task pane VBA.

Long-term: Hybrid—Shared for UI, isolated for heavy CFs.


Sources

  1. Best practices for custom functions in Excel
  2. Configure your Office Add-in to use a shared runtime
  3. Troubleshoot custom functions
  4. Excel Crashes consistently if custom functions add-in use localStorage
  5. Excel event binding issue when using shared runtime and custom functions
  6. Excel Addin is intermittently crashing on opening new excel books
  7. Troubleshoot Excel add-ins
  8. Excel custom functions in shared runtime display #BUSY!
  9. Excel Recalculation
  10. Excel shared runtime with CustomFunction not working upon service restarted

Conclusion

Excel add-in crashes in Shared Runtime boil down to multi-workbook races and volatile recalcs—well-documented in Microsoft GitHubs and docs. Nail diagnostics with F12/Event Viewer, mitigate via manual calc or runtime switch, and harden code against volatiles. Update Office, test isolated mode, and report your repro—could spark a fix. Stable sheets await; no more #VALUE! nightmares.

Authors
Verified by moderation
Moderation
Fix Excel Add-in Crashes in Shared Runtime Multi-Workbook