How to automatically name Word files from Excel
One file per record is only half the job. If the files come out as record_001.docx, somebody still has to open all 200 to find out which is which. The name has to come from a column: the invoice number, the customer, the employee ID.
Short answer: Once Word has merged, the field values are gone, so the name has to be supplied another way — either helper columns a macro can read, or a tool that never merges in the first place. Docs from Excel just asks which column to name the files from. Both routes, and the filename rules that bite, are below.
Why this is the part that hurts
Splitting a merged document is mechanical — count the sections, save each one. Naming is different, because by the time you have a merged document, the data is gone. The merged file contains the finished text, not the fields it came from. Nothing in it says "this section was row 47, customer Acme Ltd".
Every solution to this problem is really a solution to that: getting the value back at the moment the file is saved.
Approach 1: Helper columns in the data
The most widely used macros solve it by making you do the naming up front. You add columns to your spreadsheet — commonly DocFolderPath, DocFileName, PdfFolderPath, PdfFileName, spelled exactly as published, no spaces — and build the name there with a formula:
= "Invoice_" & A2 & "_" & SUBSTITUTE(B2, " ", "_")
→ Invoice_1043_Acme_Ltd
The macro reads that column when it saves. It works well and has the useful side effect that you can see every filename before anything runs. The cost is that your data file now carries four extra columns that exist purely to serve the macro.
Approach 2: Read the data source from the macro
The tidier version opens the data source itself, walks the records, and merges one record at a time — setting FirstRecord and LastRecord to the same number — so the field values are still in hand when it saves. No helper columns, more code, and it needs the data source connection to stay healthy for the whole run.
Filename rules you will hit
| Problem | What happens | Fix |
|---|---|---|
| Slashes and colons | ACME 10/2026 fails to save on Windows | Strip \ / : * ? " < > | |
| Two rows, same name | The second file silently overwrites the first | Add a unique column: ID, invoice number, row number |
| Very long names | Path length limit, save fails deep in a folder tree | Keep names short; do not put the whole address in the name |
| Trailing spaces | Windows trims them, names stop matching your records | Trim the column first |
Approach 3: Pick the column and be done
Docs from Excel never builds a merged document in the first place, so the data is still there when each file is written. You choose which column supplies the name from a dropdown — and illegal characters are stripped for you.
Template with {{placeholders}}, plus your list, out come Acme_Ltd.docx, Bright_Co.docx, one per row, in Word or PDF. No helper columns, no macro, nothing to install.
See the file names before you pay
Every file in the batch is listed by name, and any of them can be opened at full size, before any payment.
Send your Excel →Free to run and inspect. Downloading a batch is a one-time US$9.90 — no subscription, no account.