Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete blank pages from mail merged word 2003 document

Status
Not open for further replies.

bluesea2

Technical User
Dec 17, 2010
2
GB
Hi,

I have a 20 page document, each page has an identical layout with a mixture of text and tables.

I am running a mailmerge on the document which works successfully. My problem is that after the mail merge has completed, I am left with about 15 blank pages per record as their is not always data to merge for every page for each record. Does that make sense? I am printing the final document when the mail merge completes but I dont want to print lots of "blank" templates where no data was merged for that record.

Does anyone know of a macro I can run on the mail merged document which will delete the pages where no data was merged to it. To decide if a page is deleted, the condition could be something like
if mergefiled = blank or if particular cell in table is blank,
then delete complete page of document

Any advice would be greatly appreciated.
 
Does that make sense?
No, it doesn't - the mailmerge should be designed to not generate empty pages. You should be able to do this using 'IF' field tests.

Having:
15 blank pages per record
Is over the top!


Cheers
[MS MVP - Word]
 
Thanks for pointing me to the cross post link. Apologies, I can now see that it can be annoying! I was pretty desperate for an answer so posted to a few different groups.
None of my other posts had a reply, I have edited my other posts and put a link to this post as the original.


It looks like I have been trying to do this the wrong way. Will read up on IF field tests, thanks.
 
hi bluesea2,

Your mailmerge description suggests you might have many records per 'letter'. If that's the case, you can use Word's Catalogue/Directory Mailmerge facility (the terminology depends on the Word version). To see how to do so with any mailmerge data source supported by Word, check out my Microsoft Word Catalogue/Directory Mailmerge Tutorial at:
or
Do read the tutorial before trying to use the mailmerge document included with it


Cheers
[MS MVP - Word]
 
Hi Bluesea2,

Pending your implementation of the IF tests or the Catalogue/Directory mailmerge, here's a macro that will delete all empty table rows from your document:
Code:
Sub TableCleaner()
Dim oRow As Row, oTable As Table
Application.ScreenUpdating = False
For Each oTable In ActiveDocument.Tables
  For Each oRow In oTable.Rows
    If Len(Replace(oRow.Range.Text, Chr(13) & Chr(7), _
      vbNullString)) = 0 Then oRow.Delete
  Next oRow
Next oTable
Application.ScreenUpdating = True
End Sub

Cheers
Paul Edstein
[MS MVP - Word]
 
You can also get rid of blank pages without a macro, provided that they are based on 'manual page breaks'. In your standard find / replace function, change ^m^m to ^m. Run several times to get rid of all such cases.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
Hi Madawc,

From the OP's:
each page has an identical layout with a mixture of text and tables
and
if mergefiled = blank or if particular cell in table is blank,then delete complete page of document
I get the impression that the so-called blank pages are anything but. At the very least, it seems they have empty table rows and maybe some text as well.

Cheers
Paul Edstein
[MS MVP - Word]
 
Code:
    If Len(Replace(oRow.Range.Text, Chr(13) & Chr(7), _
      vbNullString)) = 0 Then oRow.Delete
Nice.

< 60 working days until retirement
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top