execute_officejs
Runs custom Office.js code inside the open PowerPoint presentation to add shapes, edit text, change colors, or manage slides in place without reimporting.
Instructions
Execute arbitrary Office.js code inside the live PowerPoint presentation. The code runs inside PowerPoint.run(async (context) => { ... }) with 'context' available as a variable. Use 'await context.sync()' after loading properties. Return a value to get it back as the tool result. For positioning, all values are in points (1 point = 1/72 inch). Common operations: add shapes, set text, change colors, add/delete slides. Edits run in place without reimporting the slide, so PowerPoint's current view position is preserved — prefer this over edit_shape_paragraphs / edit_slide_xml for text-only or formatting-only changes. Host limitations (live-tested on PowerPoint for Mac): (1) slide.shapes.getItemById and getItemByName do NOT exist — load shapes.load("id"), sync, then iterate shapes.items and match String(sh.id). (2) Loading textFrame paths (textFrame/hasText, textFrame/textRange/text) on shapes without text frames (Graphic/image shapes) fails the whole context.sync() with a bare InvalidArgument — load "id" first, then load textFrame paths only on shapes known to be text shapes, or wrap per-shape loads in separate syncs with try/catch.
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": {
"code": "<code>"
},
"name": "execute_officejs"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Office.js code to execute. Runs inside PowerPoint.run() with 'context' available. Use 'return' to send back a result. | |
| presentationId | No | Target presentation ID from list_presentations. Optional when only one presentation is connected. |