ChatGPT prompt to write an Excel VBA macro
An Excel VBA prompt for ChatGPT or Copilot that produces a reliable macro with Option Explicit, no Select or Activate, error handling, and clear instructions for enabling it.
Tuned for ChatGPT · structured role / context / task / output
Open in the builder →Ready-to-use prompt
# Role You are an experienced workflow-automation architect who designs reliable, maintainable automations on the platform in use: a precise trigger, exact connector and action names, explicit conditions, error handling, and a test plan. # Context Write an Excel VBA macro that consolidates the monthly sheets into one table and emails it to the finance team. # Task Design the automation described in the context above for the stated platform: the trigger, each action in order with exact connector or action names, the conditions and approvals, error handling and retries, and how to test it before it goes live. # How to approach this Work the problem internally, then give only the result. Do not narrate your reasoning unless it is part of the deliverable. - Lay the automation out in order: trigger, each action, the conditions and branches, error handling, then a test plan. Before you finalize, verify that the trigger fires on exactly the intended event and nothing else; every action names the real connector, action, or command for the stated platform; the first failure has a handling path: retry, notify, or stop; the test plan covers the main path and that first failure. # Constraints - Do not invent connector, action, or command names. If unsure one exists, say so and use the closest real alternative. - Follow the requested format exactly. Default to clean markdown. Be concise — no filler, no restating the question. - Deliver the single best answer rather than hedging across several. - When uncertain about a fact, API method, library name, or function signature, say so explicitly. Do not produce a plausible guess. - Do not invent citations, URLs, or package names. If you don't know one, omit it or flag that you don't. - Deliver the result directly — no apologies or meta-commentary about the prompt itself. # Output format Return only the requested output. If multiple distinct variants would clearly help, label them (e.g., "Option A", "Option B"). # Done when - the output fully answers the goal in the Context section with no missing parts
Customize this prompt
Answer a few quick questions and Promptivo re-tunes the prompt above to your exact situation.
Start the interview →Why this prompt works
Most AI-written VBA relies on Select and Activate and breaks when the user clicks elsewhere. The prompt bans that pattern and asks for range and array work.
Macros that fail mid-run leave Excel in a bad state. The prompt requires On Error handling that restores ScreenUpdating and reports the failing step.
Users forget the .xlsm and trust settings. The prompt asks for a one-line setup note so the macro actually runs.
Using this prompt in ChatGPT
For excel vba macro, ChatGPT is a strong choice — it's especially good at fast, well-structured drafts and reliable format-following. Promptivo formats this prompt the way ChatGPT works best: concise instructions, strict format adherence, no preamble.
Paste it into the ChatGPT app or chat.openai.com, then replace any bracketed details with your own. ChatGPT can over-explain, so this prompt sets an explicit format and length cap to keep the answer tight.
Tuned for ChatGPT: how it differs
| Model | What Promptivo changes |
|---|---|
| ChatGPT | Concise instructions, strict format adherence, no preamble. |
| Claude | Explicit step-by-step thinking and clearly delimited output sections. |
| Gemini | Precise phrasing with brief reasoning cues where they improve accuracy. |
| Copilot | Office-ready output that pastes cleanly into Word, Outlook, and Excel, with tables and numbered steps. |
Questions, answered
- Can ChatGPT write VBA macros?
- Yes, and the quality depends on the prompt. State the workbook layout, the sheets and columns involved, what the macro should do in order, and how it should handle errors. The output should start with Option Explicit and avoid Select.
- Should I use VBA or Power Automate?
- VBA for desktop-only workbooks and heavy in-workbook manipulation. Power Automate or Office Scripts when the workflow touches email, Teams or SharePoint, or runs on a schedule in the cloud.
- Why does Excel say macros are disabled?
- The file must be saved as .xlsm and the workbook or its location trusted in the Trust Center. The prompt includes that setup note with the macro.
- Is ChatGPT good for excel vba macro?
- Yes. ChatGPT handles excel vba macro well thanks to its fast, well-structured drafts and reliable format-following, and Promptivo tunes the prompt to match — concise instructions, strict format adherence, no preamble. Paste it into the ChatGPT app or chat.openai.com.