excel
Author and run VBA macros in a workbook via COM; check AccessVBOM trust first to prevent HRESULT 0x800a03ec failures.
Instructions
Purpose: Author and run VBA macros against Excel via COM late binding (ADR-015). Headline differentiator against Claude for Excel which writes formulas but cannot run VBA.
Details: action='run_vba' authors a Sub in a fresh workbook, saves into the managed Trusted Location (%LOCALAPPDATA%\desktop-touch-mcp\trusted-vba), and Application.Run the macro. Requires HKCU AccessVBOM=1 + VBAWarnings=1 + a registered Trusted Location (all configured by node scripts/enable-access-vbom.mjs). Trust setup: Excel must restart after the CLI runs (values cached at process start). action='check_access_vbom' is a read-only preflight returning {trusted, lockedByPolicy, scope}.
Prefer: Run check_access_vbom first when a workflow depends on macro execution; the remediation hint pre-empts an opaque HRESULT 0x800a03ec failure inside run_vba.
Caveats: macroName MUST appear as Sub <name>(...) in code (else VbaMacroNotFound). VBA Editor UI is structurally bypassed — no UIA tree walk needed. Excel COM is STA: each call serialises through the bridge's worker thread, so long-running macros block subsequent excel() calls on the same MCP server.
Examples:
excel({action:'check_access_vbom'}) → {trusted:true, scope:'hkcu'}
excel({action:'run_vba', code:'Sub DesktopTouchAdHoc()\n Range("A1").Value = "Hello"\nEnd Sub'}) → {ok:true, workbookPath:'...\trusted-vba\dt_vba_.xlsm'}
excel({action:'run_vba', code:'Sub Demo()\n MsgBox "hi"\nEnd Sub', macroName:'Demo', visible:true}) → demo recording path
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | VBA source. MUST declare at least one Sub matching `macroName` (default `DesktopTouchAdHoc`). Example: "Sub DesktopTouchAdHoc()\r\n Range(\"A1\").Value = \"Hello\"\r\nEnd Sub" | |
| action | Yes | Action selector — one of: run_vba, check_access_vbom. Per-action required fields are enforced at call time (see the tool description); this flat schema lists every action's fields as optional. | |
| include | No | Optional response-shape opt-in. `['envelope']` returns the self-documenting envelope (`_version` / `data` / `as_of` / `confidence`). `['raw']` forces raw shape (overrides DESKTOP_TOUCH_ENVELOPE=1 server default). Default behaviour is raw shape (compat with existing clients). | |
| visible | No | If true, show the Excel window during execution. Default false (headless). Setting visible:true is useful for demo recording but may surface MsgBox/InputBox calls in the macro that block the COM thread. | |
| macroName | No | Sub name to invoke. MUST appear in `code` as `Sub <name>(...)`. Default `DesktopTouchAdHoc`. | DesktopTouchAdHoc |