Excel VBA Macro Generator & Explainer
Describe a task and this excel vba macro generator writes a commented module, or paste a macro you found and get it explained line by line. Either way, a safety review of what the code can do comes first.
- Free to use
- No account required
- Instant results
- Sent to the AI only when you press the button
Explanation
Example result (nothing was sent)Safety review
Macros can change or delete files and send data. Read the code and try it on a copy of your workbook first.
Found by our detector (1)
- HighLine 15: Kill. Deletes files from disk. Deleted files do not go to the Recycle Bin.
If Dir(target) <> "" Then Kill target
Also noted by the AI
- Line 15: Kill deletes existing PDF files with the same name without sending them to the Recycle Bin.
- Line 10: Creates a new folder next to the workbook.
The macro saves each worksheet of this workbook as its own PDF file in a folder called PDF next to the workbook. It creates the folder if needed, deletes any older PDF with the same name first, and shows a message with the number of sheets exported.
Line 1
1Option ExplicitForces every variable to be declared, so typing mistakes in names are caught before the macro runs.
Lines 3–4
3' Saves every worksheet as a PDF in a "PDF" folder next to the workbook.4Sub ExportSheetsToPdf()A comment describing the macro, then the start of the procedure ExportSheetsToPdf, which you run with Alt+F8.
Lines 5–7
5 Dim ws As Worksheet6 Dim folder As String7 Dim target As StringDeclares three variables: the worksheet being processed, the output folder and the full path of each PDF.
Line 9
9 folder = ThisWorkbook.Path & Application.PathSeparator & "PDF"Builds the folder path: the workbook's own folder plus PDF, with the right separator for Windows or Mac.
Line 10
10 If Dir(folder, vbDirectory) = "" Then MkDir folderIf that folder does not exist yet, MkDir creates it.
Lines 12–13
12 For Each ws In ThisWorkbook.Worksheets13 target = folder & Application.PathSeparator & ws.Name & ".pdf"Loops over every worksheet and builds the PDF path from the sheet name.
Lines 14–15
14 ' Replace the previous export of this sheet15 If Dir(target) <> "" Then Kill targetIf a PDF with that name already exists, Kill deletes it permanently so it can be replaced.
Line 16
16 ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=targetExports the sheet to the PDF file.
Line 17
17 Next wsMoves to the next worksheet.
Lines 19–20
19 MsgBox "Exported " & ThisWorkbook.Worksheets.Count & " sheets to " & folder20End SubShows how many sheets were exported and where, then ends the procedure.
Your data: Your text is sent to our server and to the AI provider only when you press the button. We do not store it with your identity, and nothing is sent before that.
How to use
- Choose Explain VBA to understand existing code, or Generate a macro to write new code.
- Paste the code (up to 20,000 characters), or describe the task in plain English (up to 2,000 characters).
- In Explain mode, read the instant safety scan that appears under the box while you paste. It runs in your browser.
- Press Explain code or Generate macro. The answer starts with the safety review, then the explanation or the module.
- Copy the code, download it as a .bas file (File > Import File in the VBA editor), or download the explanation as Markdown.
Examples
Explaining an export macro. The example on the page is a 20-line macro that saves each worksheet as a PDF. The review flags line 15 as high severity: Kill target deletes the previous PDF without the Recycle Bin. The explanation then walks through the code in ten groups of lines, from Option Explicit to End Sub.
Spotting a downloader. A pasted macro that calls URLDownloadToFile and then Shell … vbHide gets two high-severity flags before the AI says anything. The flags read: line 2 downloads a file from the internet, and line 3 starts another program.
Generating a clean-up macro. "Delete .tmp files older than 30 days in a folder the user chooses, and ask for confirmation first" gives a module with a folder picker and a Yes/No question. The review flags the Kill on line 18 so you know it deletes files permanently.
Tips and limits
- The safety review comes from our own detector, not from the AI. It ignores text inside comments and strings, and it looks for these operations:
- running programs and typing keys: Shell, WScript.Shell, SendKeys;
- deleting files and folders: Kill, RmDir, FileSystemObject deletes;
- Windows API calls: Declare and Declare PtrSafe;
- internet traffic: URLDownloadToFile, MSXML2, WinHttp;
- the registry and system queries: RegWrite, SaveSetting, GetObject("winmgmts");
- code that runs by itself or opens other files: Application.OnTime loops, Workbooks.Open, Auto_Open and Workbook_Open, and writing to the Startup folder.
- The AI's own list of risks is shown under ours, never instead of it. A comment in the code asking the AI to call it safe does not change our flags.
- Notes cover Windows-only objects and API calls, backslash paths, and Mac-only AppleScriptTask. They also cover 32-bit versus 64-bit Office: Declare needs PtrSafe and LongPtr.
- Line ranges in an explanation that point outside your code are dropped and counted, and lines left unexplained are listed.
- Requests for keyloggers, password stealers, self-spreading code or macros that hide their behaviour are refused.
- You can send 10 AI requests per 10 minutes. Long modules can exceed the AI's input limit once line numbers are added; explain one procedure at a time.
FAQ
Is it safe to run a macro I did not write?
Only after you have read it. Start with the safety review here. A macro has the same rights as you, so it can delete files, send data or start programs. Test it on a copy of the workbook.
How do I enable macros?
Save the workbook as .xlsm. When you open it, click Enable Content on the yellow bar. If the file came from the internet, first right-click it in Windows, choose Properties and tick Unblock.
Can the tool convert VBA to Apps Script?
No. VBA and Google Apps Script use different object models. Describe the task in the Google Apps Script Generator instead.
Why does my Declare line turn red in 64-bit Office?
64-bit Office needs `Declare PtrSafe`, and LongPtr for handles. The notes say which lines need changing.
Do generated macros work on a Mac?
Macros that only use Excel objects usually do. Anything with CreateObject, Windows API calls or C:\ paths does not, and the notes point those out.
Can it explain code from Word or Access?
The explanation works for any VBA, but the generator writes Excel macros.
Privacy note
When you press Explain code or Generate macro, the pasted code or your description is sent to our server and to the AI provider to produce the answer. The instant safety scan runs in your browser and sends nothing. We do not store the text with your identity, and identical requests may be answered from a short-lived cache. The example shown when the page opens is saved in the page and sends nothing.
Guides for this tool
Spreadsheet & Formula StudioIs This Excel Macro Safe? Check VBA Before Running
How to check VBA code before you enable a macro: paste it in Explain mode, read the instant safety scan, and know what the review cannot prove.
4 min read
Spreadsheet & Formula StudioVBA Macro to Export Each Worksheet as a PDF
How to export every worksheet to its own PDF with a VBA macro: generate or explain it, read the Kill safety flag, import the .bas file and check the notes.
4 min read