Good ChatGPT prompts for VBA say which Office app you're in, describe your sheet or document layout, and spell out exactly what the macro should do, then ask for comments in the code. One thing to know first: Microsoft now blocks VBA macros by default in files from the internet, so a macro-enabled file you email or download may not run until it's unblocked.
VBA is still the quickest way to automate the repetitive bits of Excel, Word and Outlook on Windows, and ChatGPT has made it far less intimidating. Describe the job, and it'll write the macro, explain each line and fix it when it errors. The prompts below give it the details it needs about your file, and keep safety in view, because macros are also one of the oldest tricks attackers use.
Microsoft's macro rules you need to know
Everything in this table comes from Microsoft's own documentation on macros from the internet, and it's worth knowing before you share a single macro with anyone:
| What Microsoft says | What it means for you |
|---|---|
| Office blocks VBA macros by default in files from the internet, such as email attachments, and shows a Security Risk banner | A macro file you send a colleague may not run for them |
| To unblock a file you trust: right-click it, choose Properties, select Unblock on the General tab | Only do this for files you know are safe |
| The change affects Office on Windows in Access, Excel, PowerPoint, Project, Publisher, Visio and Word | Mac, mobile and web versions aren't affected by this change. Outlook isn't on Microsoft's list either |
| Files on OneDrive or SharePoint can be opened with Open in Desktop App; a downloaded local copy needs Mark of the Web removed | Send a link, not an attachment |
| A macro-enabled template on your device: remove Mark of the Web or save it to a Trusted Location. Files on a network share: designate the location as a Trusted site | Ask whoever runs your IT before changing trust settings for a whole folder |
| The Unblock-File cmdlet in PowerShell also removes the block from an individual file | Handy if you unblock files often, but the same rule applies: trusted files only |
| VBA macros are a common way for attackers to deploy malware and ransomware | Never enable macros in a file you weren't expecting |
Here's how this shows up in real life: the macro ChatGPT wrote works perfectly on your machine, then 'breaks' when a colleague opens the emailed file and sees the Security Risk banner instead. It hasn't broken. Office has blocked it because the attachment came from the internet. The cleanest fix is to keep the file on OneDrive or SharePoint and have colleagues open it with Open in Desktop App. If they've already downloaded a copy, they need to unblock that copy, as in the table above.
Prompts to write Excel macros
Describe the sheet: names, columns and where the data starts. Would rather skip the code? You can create a macro in Excel by recording your steps.
Copy this prompt
Write an Excel VBA macro for the sheet [sheet name], where data starts in row 2 and columns A to [letter] hold [describe]. The macro should [task]. Add comments explaining each step.
Copy this prompt
Write a macro that loops through every sheet in this workbook and copies the used range from each into a new sheet called Summary, with the sheet name in the first column.
Copy this prompt
Create a macro that removes blank rows from the active sheet without deleting rows that only look empty because of formulas.
Copy this prompt
Write VBA that highlights any row where the date in column [letter] is in the past and the status in column [letter] isn't Done.
Copy this prompt
Write a macro that saves each sheet in this workbook as a separate PDF in the same folder, named after the sheet.
A worked example, from prompt to running macro
Here's an illustration of how the first prompt plays out. Say you have a sheet called Orders with headers in row 1 (Date in column A, Client in B, Status in C) and data from row 2. The filled-in prompt reads: Write an Excel VBA macro for the sheet Orders, where data starts in row 2 and columns A to C hold the order date, the client name and a status. The macro should highlight every row where the date is in the past and the status isn't Done. Add comments explaining each step.
What comes back will look something like this. Your version may differ line by line, which is fine as long as it names your real sheet and columns:
Sub HighlightOverdueOrders()
' Highlights rows on Orders where the date has passed and Status isn't Done
Dim ws As Worksheet
Dim lastRow As Long, r As Long
Set ws = ThisWorkbook.Worksheets("Orders")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For r = 2 To lastRow
If IsDate(ws.Cells(r, "A").Value) Then
If ws.Cells(r, "A").Value < Date And ws.Cells(r, "C").Value <> "Done" Then
ws.Range("A" & r & ":C" & r).Interior.Color = RGB(255, 235, 156)
End If
End If
Next r
End Sub
To run it in Excel on Windows:
- Make a copy of the workbook and open the copy.
- Press Alt+F11 to open the VBA editor.
- Choose Insert > Module and paste the code into the blank window.
- Click anywhere inside the Sub and press F5 (or use Run).
- Save the file as an Excel Macro-Enabled Workbook (.xlsm). Save it as a normal .xlsx and Excel drops the code.
Prompts for Word and Outlook macros
Same approach: describe the document or mailbox job precisely.
Copy this prompt
Write a Word VBA macro that finds every instance of [text] in the active document and makes it bold, then tells me how many it changed.
Copy this prompt
Write a Word macro that applies the Heading 2 style to every paragraph that starts with a number followed by a full stop.
Copy this prompt
Write an Outlook VBA macro that saves attachments from selected emails into a folder I choose, skipping signature images.
Copy this prompt
Write a macro that inserts today's date and my standard header text at the top of a new Word document.
Prompts to fix and understand VBA
For inherited macros and error messages.
The error you'll probably meet first is Run-time error 9 (Subscript out of range). With ChatGPT code it usually means the macro refers to a sheet name that doesn't exist in your file, because ChatGPT guessed Sheet1 or Data when your tab is called Orders. The fix is to give the exact tab names in your prompt. For anything else, click Debug, copy the exact error text and the line the editor highlights in yellow, and paste both into the first prompt below.
Copy this prompt
This macro stops with the error [paste error] on the line [paste line]. Explain why and give me a corrected version: [paste code].
Copy this prompt
Want AI doing the heavy lifting in your marketing?
I build the systems that handle the boring 80 percent, so you get your week back. Done properly, with the human kept in.
Explain this macro line by line in plain English and tell me what it changes in my file: [paste code].
Copy this prompt
This macro is very slow. Suggest changes, such as turning off screen updating, and explain why each one helps: [paste code].
Copy this prompt
Add error handling to this macro so it shows a clear message instead of crashing, and restores settings it changed: [paste code].
Prompts for safer macros
Build the safety in, especially for macros that delete or overwrite.
Copy this prompt
Before this macro deletes anything, add a confirmation message that says how many rows will be removed and lets me cancel.
Copy this prompt
Change this macro so it works on a copy of the sheet rather than the original: [paste code].
Copy this prompt
Review this macro I found online and tell me everything it does, including anything that connects to the internet, runs other programs or changes files outside the workbook: [paste code].
Copy this prompt
Explain the safest way to share a macro-enabled workbook with my team, given that Office blocks macros in files from the internet.
Prompts for learning VBA
If you want to understand it, not just use it.
Copy this prompt
Teach me the basics of VBA in Excel with five tiny examples I can run, each building on the last.
Copy this prompt
Explain the difference between a Sub and a Function in VBA with a simple example of each.
Copy this prompt
Give me three beginner VBA exercises based on a simple sample sheet you describe, such as a task list, with solutions at the end.
How to get better VBA from ChatGPT
- Say which app and describe the layout: sheet names, columns, header row and where data starts.
- Ask for comments in the code so you can follow and edit it later.
- Test on a copy of your file first, especially for macros that delete or overwrite.
- Ask ChatGPT to explain any macro you didn't write before you run it.
- Remember the internet block: unblock only files you trust, or share through OneDrive's Open in Desktop App.
- Save Excel files as .xlsm, or the macro is gone the next time you open the file.
- When it errors, paste the exact error text and the highlighted line back into the same chat, so ChatGPT fixes its own code rather than starting again.
If you'd rather avoid macros, my guide to Claude for Excel shows another way to automate spreadsheet work, and Microsoft's Copilot now handles some of these jobs inside Office. My office productivity tips cover the quick wins that need no code at all.
My advice on ChatGPT prompts for VBA
Run one macro at a time, on a copy of the file, and read ChatGPT's explanation before you press F5. Describe your file precisely, ask for comments, test on a copy and add confirmation steps to anything destructive. And respect Microsoft's macro block rather than fighting it: it exists because macros are a favourite way into a business. If you only try one prompt from this page, make it the PDF-per-sheet macro: it turns a dull end-of-month job of exporting each sheet by hand into a single click.
I run AI training and workshops for teams, and help businesses with AI enablement and workflow automation, so the busywork runs itself and people get time back. Most of that work is with SaaS marketing teams and small businesses. Here's how we can work together.
Frequently asked questions
How do I open the VBA editor?
In Excel or Word on Windows, press Alt+F11, then choose Insert > Module and paste the code. Save Excel files as .xlsm so the macro stays in the file.
Why won't my macro run in a downloaded file?
Microsoft says Office blocks VBA macros by default in files from the internet, such as email attachments, and shows a Security Risk banner.
How do I unblock macros in a file I trust?
Microsoft says to right-click the file, choose Properties and select the Unblock checkbox on the General tab. Only do this for files you trust.
Does Microsoft's macro block cover Outlook?
Microsoft's list of affected apps is Access, Excel, PowerPoint, Project, Publisher, Visio and Word, on Windows only. Outlook isn't on it.
What if my macro file is on OneDrive?
Microsoft says to open it with Open in Desktop App. A copy you've downloaded to your computer needs unblocking first.
Is it safe to run VBA code from ChatGPT?
Usually, if you understand it. Ask ChatGPT to explain the macro first, test it on a copy, and never run code that touches files or the internet unexpectedly.


