PDA

View Full Version : Mail Merge into table but have empty rows not appear



mcarlson88
06-17-2015, 09:20 AM
Hello,

As the title says I have a mail merge with 10 rows populating with fields, currently I am using rules to have text appear along with the field in each of the rows. I would like the other (empty) rows of the table to disappear if there are no values in those fields.

Please forgive me if this is the incorrect place to post.

excelliot
06-19-2015, 12:57 AM
which version of Office you are using..

excelliot
06-19-2015, 01:07 AM
you can use if condition in 2007, check this http://word.mvps.org/Faqs/MailMerge/MMergeIfFields.htm

gmayor
06-19-2015, 01:35 AM
A merge to variable length table suggests a many to one mail merge, in which case I would suggest - http://www.gmayor.com/ManyToOne.htm
If not a many to one merge, then there is no simple way to conditionally merge table rows. You would either have to create your own merge process in VBA to create the rows of the table on the fly, or you could merge to a new document and process that document to remove the empty rows. The latter is simpler. In the macro example below if the first cell in any row is empty then the row is deleted. You can modify that to suit what you have.



Sub DeleteEmptyRows()
Dim oTable As Table
Dim oRow As Row
For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
If Len(oRow.Cells(1).Range) = 2 Then
oRow.Delete
End If
Next oRow
Next oTable
End Sub

excelliot
06-19-2015, 01:49 AM
I guess your code would delete all blanks even if they have not created using mail merge..

Cheers!!