agentsclimarketplace

Excel vba headless debug

Skill reiseah86-gif/claude-vba-debug-plugin/skills/excel-vba-headless-debug

Test and debug Excel VBA macros run headlessly through PowerShell/COM automation (no visible Excel window). Use this whenever the user is iterating on a VBA macro, mentions testing an .xlsm/.xlsb workbook via COM/PowerShell, hits a run-time error while testing a macro, or reports Excel "hanging" or "freezing" during headless automation — that hang is almost always a stuck dialog this skill knows how to diagnose. Also use when the user wants Claude to automatically catch, diagnose, and fix VBA errors during macro development rather than manually re-running and eyeballing what broke.From its SKILL.md

Install
npx -y skills add reiseah86-gif/claude-vba-debug-plugin --skill excel-vba-headless-debug

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

6.1 KB, as published. Nobody here has run it

Headless Excel VBA Test & Debug

Why this exists

Testing a VBA macro through Excel's COM automation interface with no visible window is fast and scriptable, but it breaks the normal way you'd notice something went wrong: a Run-time error 'N' dialog needs a human to click it. In headless automation nobody's there, so:

  • If the macro has no error handling, an unhandled error tries to pop a dialog — and since nothing can dismiss it, the whole process just hangs forever.
  • Even with DisplayAlerts = False, that setting doesn't suppress MsgBox/InputBox calls or an unhandled runtime error dialog — only Excel's own built-in alerts.

So "detecting the error" headlessly is really two separate problems: catching errors that do get reported (via a logging wrapper) and catching the ones that would hang the process (via a timeout watchdog that treats a hang itself as a signal). This skill handles both, then uses the result to diagnose and fix the underlying VBA.

Prerequisites (one-time, on the user's machine)

Before this works at all, "Trust access to the VBA project object model" must be enabled: Excel > File > Options > Trust Center > Trust Center Settings > Macro Settings. Without it, any attempt to read or inject into VBProject throws a COM error immediately. If the very first run fails with something like "Programmatic access to Visual Basic Project is not trusted," this is the fix — tell the user to enable it and try again.

Workflow

1. Identify the entry point

Confirm with the user (or infer from their existing PowerShell script) the workbook path and the macro entry point in Module.ProcName form — this is what gets passed to Application.Run. Everything below assumes you know this.

2. Run the test harness

Use scripts/test_vba_macro.ps1:

.\test_vba_macro.ps1 -WorkbookPath "C:\path\to\Workbook.xlsm" -MacroName "Module1.RunTest" -TimeoutSeconds 30

This orchestrator launches scripts/run_macro_headless.ps1 as its own child process (so a hang can be killed from outside) and returns a JSON result with one of these status values:

  • success — ran clean, nothing logged.
  • error — a VBA runtime error was caught and logged, with errorNumber, errorDescription, and procedure.
  • timeout — the process didn't finish in time. Read references/vba_error_codes.md's "Headless-specific gotchas" section — this is almost always a stray MsgBox/InputBox or a dialog DisplayAlerts didn't suppress, since a real logged error would have returned quickly instead of hanging.
  • injection_failed — couldn't access the VBA project, almost always the Trust Center setting above.
  • automation_exception — the error escaped even the injected handler (rare — usually a compile error in the VBA itself, which prevents the code from running at all).

The first time you run this against a given macro, run_macro_headless.ps1 injects a logging error handler into the target procedure automatically (wrapping it in On Error GoTo + a handler that appends timestamp|errNumber|errDescription|procName|line to the log file). This injection is idempotent — it checks for a marker comment before inserting, so re-running the harness repeatedly won't stack up duplicate handlers.

Note what this wrapper does and doesn't catch: it's inserted only in the entry-point procedure, not every Sub/Function the macro calls. In VBA, an unhandled error in a called procedure propagates up the call stack until it finds an active handler, so one wrapper at the entry point catches errors from anything it calls unless a downstream procedure has its own On Error Resume Next that silently swallows the error first. If results seem to be missing an error you know is happening, check for that.

3. Diagnose

Once you have an error result, cross-reference errorNumber against references/vba_error_codes.md for the likely cause, then actually read the VBA source around procedure (via the same CodeModule.Lines approach used for injection) to confirm which specific line matches that cause — the table narrows down the category, but the actual fix has to match the real code in front of you.

4. Fix and verify

Edit the VBA source directly (via CodeModule.ReplaceLine / DeleteLines + InsertLines), then re-run step 2 to confirm the fix actually resolves it. Cap this at around 3 attempts — if the same error (or a new one) keeps surfacing after 3 fix attempts, stop and report back what was tried and what's still failing rather than guessing further. Don't loop silently; tell the user what changed at each attempt.

5. Offer cleanup

The injected error handler is debug scaffolding. Once the user is satisfied the macro works, offer to strip it back out (remove the On Error GoTo line and handler block) so production code doesn't carry the extra scaffolding — but leave it in if they're still actively iterating, since removing and re-injecting on every run is wasted work.

Files

  • scripts/run_macro_headless.ps1 — owns the Excel COM instance for a single run: opens the workbook, injects the handler if missing, runs the macro, closes cleanly.
  • scripts/test_vba_macro.ps1 — the orchestrator to actually invoke; wraps the above in a timeout watchdog and returns structured JSON.
  • references/vba_error_codes.md — common Err.Number values, their typical causes, and the headless-specific failure modes (stuck dialogs, .Select/.Activate issues) that don't show up as a numbered error at all.

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.