How to Attach Files by Name or Folder Path in Mail Merge
You can attach a Drive file by typing its name in the File Attachments column. A formula can fill the names or folder paths for hundreds of rows using an ID or another column in your sheet. The files must already exist in Drive. The formula builds the references to the files, not the files themselves.
If you’d rather not add a formula to the sheet, an Embed File marker in the message can build the same path, like {{Embed File, Report Cards/Class 8B/{{Student ID}}.pdf}}. See attach files by a naming pattern.
Google Sheet
| First Name | File Attachments |
|---|---|
| Angus | Report Cards/Class 8B/S-2041.pdf |
| Alice | Report Cards/Class 8B/S-2042.pdf |
| John | Report Cards/Class 8B/S-2043.pdf |
Emails sent
- To: AnguspdfS-2041.pdf
- To: AlicepdfS-2042.pdf
- To: JohnpdfS-2043.pdf
Elizabeth teaches Class 8B and wants to email each parent their child’s report card. The report cards are PDFs in a Drive folder called Class 8B, inside a folder called Report Cards. Each PDF is named after the student’s ID, like S-2041.pdf. Her mail merge sheet has each parent’s name and email address next to their child’s student ID.
Attach a File by Name
Section titled “Attach a File by Name”Type the file’s name in the recipient’s File Attachments cell, exactly as it appears in Google Drive, with the extension:
S-2041.pdfGoogle Docs, Sheets and Slides have no extension in Drive, so type the name alone, like Statement of Work. The add-on attaches the file as Statement of Work.pdf.
A name is enough when no other file in your Drive has the same name. If last year’s S-2041.pdf is also in your Drive, add the folder path. Otherwise, Mail Merge may attach the wrong file when you send.
Add the Folder Path
Section titled “Add the Folder Path”Put the folder path in front of the name, with a slash between each folder. Mail Merge then attaches the right file even when other folders have a file with the same name.
Report Cards/Class 8B/S-2041.pdf
The path doesn’t need to start at My Drive. The add-on looks for the first folder, Report Cards, anywhere in your Drive, then goes down from there. Start the path with a folder whose name is unique, so the add-on can’t pick a different folder with the same name.
Backslashes work too, so older sheets with paths like Report Cards\Class 8B\S-2041.pdf still work. Use forward slashes for new paths to keep them easy to read.
Use Formulas in Sheets
Section titled “Use Formulas in Sheets”Start with this layout. Row 1 contains the headers. The student ID is in column C, and the attachment formula goes in column D. First Name and Email Address belong to the parent receiving the report.
| First Name | Email Address | Student ID | File Attachments |
|---|---|---|---|
| Angus | angus@gmail.com |
S-2041 | Enter the formula here |
| Alice | alice@gmail.com |
S-2042 | Fill down from row 2 |
| John | john@gmail.com |
S-2043 | Fill down from row 2 |
-
Click D2, the first File Attachments cell. C2 contains
S-2041. -
Enter this formula. It joins the folder path, the student ID in column C and the file extension
.pdf.=IF(C2="", "", "Report Cards/Class 8B/"&C2&".pdf") -
Select D2, then drag the small blue dot at its bottom-right corner down to the last recipient. In D3, the formula uses C3 and produces
Report Cards/Class 8B/S-2042.pdf, Alice’s child’s report card.

Each & joins two parts. The IF leaves the attachment cell blank when the ID is empty.
Fill the Whole Column with One Formula
Section titled “Fill the Whole Column with One Formula”For a longer list, use this array formula instead of filling down manually. Put the formula in D2 and leave D3 and all cells below it empty. The formula writes a path for every row with an ID and leaves the rest blank:
=ARRAYFORMULA(IF(C2:C="", "", "Report Cards/Class 8B/"&C2:C&".pdf"))Use either the filled-down formulas or the array formula, not both. If Sheets says the array result couldn’t expand, clear the existing values and formulas below D2 first.
Attach a File Only When a Condition Is Met
Section titled “Attach a File Only When a Condition Is Met”Say column F is called Payment Status. To attach a fee receipt only when the column says Paid and the student ID is present, use:
=ARRAYFORMULA(IF(C2:C="", "", IF(F2:F="Paid", "Receipts/"&C2:C&".pdf", "")))Files with the Same Name
Section titled “Files with the Same Name”Use a folder path only when the path identifies one file. If you have last year’s and this year’s S-2041.pdf in separate folders, include the correct folder in the path. If the path is still ambiguous, select the exact file with a Drive link or file chip.
You can also list the files in a folder. In the File Attachments tab that Mail Merge creates, check the Folder and File Url columns to tell same-name files apart. Then pick one from the dropdown. Each entry ends with its Drive ID in parentheses, like S-2041.pdf (1aB3…). The ID tells Mail Merge exactly which file you picked.
When the File Name Has a Comma or Slash
Section titled “When the File Name Has a Comma or Slash”A comma separates attachments. For example, S-2041.pdf, Notes.pdf attaches two files. Mail Merge treats a comma inside one filename the same way. It reads Smith, John.pdf as Smith and John.pdf. A semicolon also separates attachments.
A slash separates folders and files. Mail Merge reads Report 11/2026.pdf as a file called 2026.pdf inside a folder called Report 11, even if the slash is part of the file’s name. A backslash (\) works the same way. These rules also apply to the folder names in a path.
Rename the file or folder in Drive, then enter its new name in the sheet. Names such as Smith John.pdf and Report 11-2026.pdf avoid these separators. To keep the original name, attach the file with a Drive link or a smart chip.
Check Before You Send
Section titled “Check Before You Send”A formula can build a path that looks right even when the file doesn’t exist, so check more than row 2. Send test emails for the first, a middle and the last row, and open each PDF to check the student ID. See check before you send for how to test other rows and do a dry run.
If a name or path doesn’t match a file, Mail Merge doesn’t send that row. Fix the reference, then clear only that row’s status to retry the row. See fix rows that weren’t sent.
Things to Know
Section titled “Things to Know”- Names must match the file in Drive, including spaces and an uploaded file’s extension. Google Docs, Sheets and Slides have no extension in Drive. Mail Merge attaches them as PDFs.
- If two files have the same name and path, Mail Merge may attach either one. Rename one, or use the intended file’s Drive link or chip.
- Mail Merge looks up names and paths in My Drive and in files shared with you, not in shared drives. Attach files in a shared drive with a Drive link or a smart chip.
- Mail Merge never attaches files in the trash.
- You can attach only Drive files by name. A path on your computer, like
C:\Reports\S-2041.pdf, doesn’t work. Upload the files to Drive first. - If a cell has a chip, Mail Merge ignores typed names and paths in that cell. Use one or the other in each cell.
