Quote:
Originally Posted by macropod
You could add the following macro to your mailmerge main document. When you click on Finish & Merge>Edit Individual Documents, the macro will automatically delete all table rows where the last cell on a given row is empty.
Code:
Sub MailMergeToDoc()
Application.ScreenUpdating = False
Dim Tbl As Table, r As Long, c As Long
ActiveDocument.MailMerge.Execute
With ActiveDocument
For Each Tbl In .Tables
With Tbl
c = .Columns.Count
For r = .Rows.Count To 2 Step -1
If Split(.Cell(r, c).Range.Text, vbCr) = 0 Then .Rows(r).Delete
Next
End With
Next
End With
Application.ScreenUpdating = False
End Sub
|
Mail Merge Table - suppress blank rows
I have a similar issue with an invoice letter mail merge where I have a 5 row table, 1 header row and 4 rows for the invoice lines. Row 2 will always have data in but 3, 4 & 5 may be blank or populated with data. Unfortunately I have no knowledge of VBA and am unsure what I need to do with Paul's sample code. I have created a module in the VBA editor, pasted in Paul's code and saved as a macro enabled file, ran the finish and merge and still got blank rows in the table. Where in the sample code do I add the row numbers that may be blank?