How to Remove Blank Mail Merge Rows and Create Individual Word Files
Question details
The user needs to remove empty table rows generated during a mail merge when records are fewer than the table's capacity, and wants to save each merged customer record as an individual file.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating invoices or forms using mail merge where the number of items per customer varies, resulting in unwanted blank rows and a need for separate output files.
- Observed behavior
- The mail merge creates empty rows to fill the maximum table size, and generates a single combined document instead of individual files per customer.
Ensure your main mail merge document is correctly linked to your data source, and make a backup copy of your document before running macros or installing external add-ins.
Use a VBA Macro to Delete Blank Rows Post-Merge
Run a VBA macro on the merged output document to automatically detect and delete rows that contain no text.
This macro is executed after the standard mail merge is completed. It targets the newly generated document and scans all tables, removing only the rows that are completely empty.
Perform your standard mail merge to generate a new document containing all records.
Press Alt + F11 to open the Microsoft Visual Basic for Applications window, then click Insert > Module.
Copy and paste the following code: Sub MailMergeToDoc() Application.ScreenUpdating = False Dim tbl As Table, r As Long ActiveDocument.MailMerge.Execute For Each tbl In ActiveDocument.Tables For r = tbl.Rows.Count To 1 Step -1 If Len(tbl.Rows(r).Range.Text) = tbl.Rows(r).Cells.Count * 2 + 2 Then tbl.Rows(r).Delete Next r Next tbl Application.ScreenUpdating = True End Sub
Press F5 or click the Run button to execute the script and clean up the blank rows.

Use the Merge Tools Add-in for Separate Files
Install a specialized third-party add-in to handle complex many-to-one merges and automatically save individual files.
Use a DATABASE Field
Insert a dynamic DATABASE field to pull only the required rows directly from the source.
Easily Handle Mail Merges and Separate Files in WPS Writer
WPS Writer streamlines the mail merge process by natively supporting the splitting of merged documents into individual files without requiring external add-ins. You can also run standard VBA macros to automate row cleanup.
- 1. Start Mail Merge: Open your template in WPS Writer, go to the Mailings tab, and click Open Data Source to link your spreadsheet.
- 2. Split the Document: After inserting your merge fields, click on 'Merge to Different New Document' on the ribbon.
- 3. Run Cleanup Macros: Use the built-in Developer tab to access the VBA Editor and run scripts to remove any leftover blank rows.

Frequently Asked Questions
Why does my mail merge leave blank rows in the invoice table?
When your Word document table is built with a fixed maximum number of rows, customers who have fewer items will leave the remaining rows empty during the mail merge process.
Can I merge directly to individual PDF files instead of Word documents?
Yes. By using the Merge Tools Add-in or using the built-in splitting features in software like WPS Office, you can set the output format to save each merged customer record as an individual PDF.
Will the VBA macro delete rows that contain formulas?
No, the provided VBA macro is specifically written to delete only rows that are completely empty. If a row contains hidden formulas, spaces, or other non-visible characters, it will not be deleted.




