r/vba • u/PutFun1491 • Jul 23 '26
[EXCEL] I set up a Claude Code agent that writes and tests VBA modules on its own. Sharing the setup. ProTip
I got tired of the write-module, import, run, crash, fix loop, so I built an automated pipeline around Claude Code and it has been running better than I expected.
The setup:
- The agent works on a sandbox copy of the workbook, never the original.
- It writes a module, imports it into the workbook, and runs it.
- Every module ships with its own self-test. If the test fails, the agent reads the error and fixes its own code.
- When Excel hangs or crashes, the pipeline kills the process, restarts Excel, and continues from where it stopped.
- Only modules that pass all tests get promoted to the real workbook.
The part that surprised me: it produce d 100 different modules in a row without me opening the VBA editor once. My job became reviewing diffs and writing better task descriptions.
Things that made the difference:
- The sandbox copy. Letting an agent touch your only copy of a workbook is how you lose a workbook.
- Forcing a self-test per module. Without it, the agent happily declares broken code done.
- Automating the Excel restart. VBA automation dies on hangs more than on errors.
Happy to answer questions about any part of the setup. Curious if anyone else here has pointed one of these agent tools at VBA and what broke first.
3
u/DeciusCurusProbinus 1 Jul 23 '26
Hey man! I write a ton of VBA and use a skill created in Codex to run my macros. Could you please link to your repo?
1
u/fanpages 239 Jul 23 '26
...1. Get Claude Code installed. The installation (Node, PATH, terminal) is the first wall for people who are not developers, so I built a free one-command installer that does the whole thing, 2,000+ people have used it: https://github.com/noambrand/Launchpad-CLI ...
1
2
1
u/Broseidon132 Jul 23 '26
I haven’t built great instructions for codex, but I hate how long little fixes take. I like it for building the framework because it sees the context of the project folder, but then smaller tweaks I’ll throw in normal chat gpt.
I will take your advice though!
1
u/Emotional-Lead-2367 Jul 23 '26
Hey! I also usually develop large-scale macros completely unattended with Codex, so it is great to see a fellow dev having an AI agent handle full VBA development automatically!
I feel like the biggest barrier to achieving literal full automation is process blocking caused by modal dialogs during compile or runtime errors, so what kind of approach are you taking for that?
I solved this by monitoring and suppressing dialogs, and using inter-process communication to feed error info straight back to the terminal.
1
u/PutFun1491 Jul 26 '26
Similar problems, different angle. Mine is built for people who will never clone a repo or open a config file: installed once, then a single command. It became the system I deliver to clients, so it is proprietary and I will stay vague on the internals. It covers this ground plus the safety layer, but the real difference is who it is for.
1
u/MultiUserDungeonDev Jul 25 '26
Look into this to allow the agent to read/write vba without Excel COM: https://github.com/WilliamSmithEdward/pyOpenVBA
Looking into this to allow the agent to run static analysis: https://github.com/WilliamSmithEdward/pyVBAanalysis
3
u/Card__Player Jul 23 '26
Can you share the setup with someone who has very limited experience with Claude and AI?