Control Microsoft Office applications from AutoHotkey v2 using ComObject and ComObjActive

domain: desktop-automation · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a new instance of an Office app with `app := ComObject("Word.Application")` (or `"Excel.Application"`), which starts the process if it isn't running
  2. Set `app.Visible := true` if you want to see the automation happen instead of running it fully in the background
  3. Attach to an already-running instance instead of launching a new one with `ComObjActive("Word.Application")`, wrapped in `try`/`catch` since it throws if no instance is registered
  4. Drive the app through its COM object model exactly as in VBA, e.g. `app.ActiveDocument.FullName` or, for Excel, `xl.Workbooks.Add()` then `xl.Cells(1,1).Value := "Hello"`
  5. Use `ComObjGet(Name)` when you need a reference to an object a COM component exposes by name/moniker rather than creating or attaching to the whole application
  6. Remember `ComObject()`/`ComObjActive()` are the v2 function names — AutoHotkey v1 scripts used `ComObjCreate()` instead, so v1 COM snippets need renaming, not just syntax translation, to run under v2

Known gotchas

Related routes

Automate Windows desktop GUI applications with AutoHotkey v2 using hotkeys and control interactions
autohotkey.com · 6 steps · unrated
Write AutoHotkey v2 scripts for window targeting, hotkeys, and GUI automation
autohotkey.com · 5 steps · unrated
Migrate an AutoHotkey v1 script to v2 syntax without breaking hotkeys and functions
autohotkey.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans