Skip to main content
Glama

excel

Author and run VBA macros in workbooks via COM late binding, with a preflight trust check to prevent opaque execution 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; the workbook is removed once the macro has run (workbookPath names where it ran from), so a macro that must keep results writes them to its own file, not ThisWorkbook. 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. A runtime error in the macro fails the call with its VBA error number and text. A macro still running after timeoutSeconds (default 30 for a hidden run; a visible run only when given) has its Excel ended and fails the call: a compile error, MsgBox / InputBox, End or an endless loop would otherwise never return. 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

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "action": "<action>"
    },
    "name": "excel"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeNoVBA source. MUST declare at least one Sub matching `macroName` (default `DesktopTouchAdHoc`). Example: "Sub DesktopTouchAdHoc()\r\n Range(\"A1\").Value = \"Hello\"\r\nEnd Sub"
actionYesAction 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.
includeNoOptional 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).
visibleNoIf 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.
macroNameNoSub name to invoke. MUST appear in `code` as `Sub <name>(...)`. Default `DesktopTouchAdHoc`.DesktopTouchAdHoc
timeoutSecondsNoHow long the macro may run. Past it, this run's Excel is ended (unsaved work in it is lost) and the call fails with VbaMacroExecutionFailed: a VBA dialog (a compile error, MsgBox, InputBox), `End`, or an endless loop would otherwise keep the call from returning. Default 30 for a hidden run; a visible run is not timed unless this is given.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv2.4.1
    • addedInput schema / properties / timeoutSeconds
      Added value: +{
      +  "description": "How long the macro may run. Past it, this run's Excel is ended (unsaved work in it is lost) and the call fails with VbaMacroExecutionFailed: a VBA dialog (a compile error, MsgBox, InputBox), `End`, or an endless loop would otherwise keep the call from returning. Default 30 for a hidden run; a visible run is not timed unless this is given.",
      +  "maximum": 3600,
      +  "minimum": 1,
      +  "type": "integer"
      +}
  2. Changed8 schema fields changedv2.3.1
    • addedInput schema / $schema
      Added value: +"http://json-schema.org/draft-07/schema#"
    • removedInput schema / additionalProperties
      Removed value: -true
    • addedInput schema / properties / action
      Added value: +{
      +  "description": "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.",
      +  "enum": [
      +    "run_vba",
      +    "check_access_vbom"
      +  ],
      +  "type": "string"
      +}
    • addedInput schema / properties / code
      Added value: +{
      +  "description": "VBA source. MUST declare at least one Sub matching `macroName` (default `DesktopTouchAdHoc`). Example: \n\"Sub DesktopTouchAdHoc()\\r\\n    Range(\\\"A1\\\").Value = \\\"Hello\\\"\\r\\nEnd Sub\"",
      +  "minLength": 1,
      +  "type": "string"
      +}
    • addedInput schema / properties / include
      Added value: +{
      +  "description": "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).",
      +  "items": {
      +    "type": "string"
      +  },
      +  "type": "array"
      +}
    • addedInput schema / properties / macroName
      Added value: +{
      +  "default": "DesktopTouchAdHoc",
      +  "description": "Sub name to invoke. MUST appear in `code` as `Sub <name>(...)`. Default `DesktopTouchAdHoc`.",
      +  "minLength": 1,
      +  "type": "string"
      +}
    • addedInput schema / properties / visible
      Added value: +{
      +  "default": false,
      +  "description": "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.",
      +  "type": "boolean"
      +}
    • addedInput schema / required
      Added value: +[
      +  "action"
      +]
  3. Addedv1.12.0
  4. Removedv1.10.4
  5. Addedv1.9.2
  6. Removedv1.8.0
  7. Addedv1.6.0
  8. Removedv1.5.1
  9. Addedv1.5.0

TDQS

A4.2/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full behavioral burden and does so thoroughly: it discloses the Trusted Location path, that the workbook is removed after execution, registry prerequisites, the need to restart Excel, STA serialization and blocking behavior, timeout consequences, and how macro runtime errors surface.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but appropriately structured with Purpose, Details, Prefer, Caveats, and Examples, and the core purpose is front-loaded. Some material, such as the Claude for Excel differentiator and the architectural note about bypassing the VBA Editor UI, is less essential for invocation but still useful context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex COM-based macro tool with no annotations and no output schema, the description covers prerequisites, failure modes, timeout behavior, and example return shapes well. The main remaining gap is routing relative to the run_macro sibling, which would help an agent choose correctly between macro-execution tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds substantial meaning beyond schema: action='run_vba' creates a fresh workbook in the managed Trusted Location and removes it afterward, action='check_access_vbom' is a read-only preflight returning {trusted, lockedByPolicy, scope}, and macroName must match a declared Sub in code.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: author and run VBA macros against Excel via COM late binding. It clearly distinguishes the two actions, run_vba and check_access_vbom, but does not differentiate itself from the sibling run_macro tool, leaving an agent to infer which macro-execution tool to use.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit preflight guidance: run check_access_vbom first when a workflow depends on macro execution, and explains that this pre-empts an opaque HRESULT failure in run_vba. However, it does not state when to prefer this tool over the run_macro sibling or when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.