Metadata-Version: 2.4
Name: vba
Version: 0.1.0
Summary: Read, change, debug and install VBA for Word, Excel and PowerPoint, as a command line and an MCP server
Keywords: vba,macro,word,excel,powerpoint,office,mcp
Author: Keyor
License-Expression: AGPL-3.0-or-later
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Office/Business :: Office Suites
Classifier: Programming Language :: Python :: 3
Requires-Dist: pyopenvba==6.6.0
Requires-Python: >=3.11
Project-URL: Homepage, https://github.com/superkeyor/vba
Description-Content-Type: text/markdown

# vba

Read, change, debug and install VBA for Word, Excel and PowerPoint, from the command line or an MCP client.

- Reads and writes the macros inside Office files with [pyOpenVBA](https://pypi.org/project/pyopenvba/). No Office needed.
- On a Mac, loads changed code into the running app without a restart and runs it on one file.
- Installs finished code in your macro file: backed up, checked, and only while the app is closed.

## What works where

| | Mac | Windows | Linux |
|---|---|---|---|
| `list`, `pull`, `install` | Yes | Yes, but not yet tried on a real PC | Same, with `--file` |
| `load`, `run`, `exec`, `unload`, `status` | Yes | No | No |
| Default macro files | Found | Looked for in `%APPDATA%\Microsoft` | None |
| `mcp` | All tools | `vba_help`, `vba_list`, `vba_pull` | `vba_help`, `vba_list`, `vba_pull` |

Live control uses AppleScript. Windows would need a version for COM, which is not written.
Until then, on Windows: test a change in the VBA editor, then `install` it with the app closed.

## Run

```bash
uvx vba --help                        # needs only uv
uvx --from /path/to/vba vba --help    # from a checkout
```

`vba --help` is the reference for commands, defaults and limits.

## MCP

```json
{
    "command": "uvx",
    "args": ["vba", "mcp"]
}
```

The server runs VBA in your open Office apps, so a client can do whatever VBA can.
It has no `install`, and Excel files are always copied first.

## How live loading works

| | Dev add-in | Loaded by |
|---|---|---|
| Word | `VBADev.dotm` in the Word startup folder | AppleScript `add addin` |
| Excel | `VBADev.xlam` in the Add-Ins folder | A loader add-in in the Excel startup folder |
| PowerPoint | `VBADev.ppam` in the Add-Ins folder | AppleScript `register add in` |

An app reads an add-in only when it loads it, so each update is unload, replace, load.
`run` and `exec` add a caller to the code that checks the target file, catches errors and returns a function's value.

## Limits

- Code that does not compile, or a `MsgBox`, opens a dialog that you must answer.
  Until then the tool sends the app nothing, because Excel quits on a command sent during a dialog.
- An endless loop blocks the app.
- A macro acts on the active file. The target is checked just before it runs.
- Undo: Word and PowerPoint only. Files a macro writes or deletes cannot be undone.
- No breakpoints or stepping; use the VBA editor for those.

## Test

```bash
PYTHONDONTWRITEBYTECODE=1 uv run --no-project --with-editable . --with pytest pytest -p no:cacheprovider
```

## License

AGPL-3.0-or-later
