Word: Propagate Labels in Label MailMerges

Home Up

 

 

Google
 


 

The Problem

When you create a Word MailMerge to print Labels, you set up the first label with the fields and text that you need,  then use the Propagate Labels function to copy that label's layout to all the other labels. Except that the Propagate Labels function does not work - for example, it fills the first row of labels and the last two labels on the page, but none of the others.

Background

This particular problem can occur on Tablet PCs running Windows XP Tablet Edition SP2 and Word 2003 or Word 2007. There is a small amount of evidence that the problem may also occur on Windows Vista, but certainly similar symptoms have been reported.

Workarounds

The following Microsoft Knowledgebase article describes the problem and some possible workarounds:

"Merge fields do not replicate in labels in a mail merge document in Word 2007 or Word 2003 on a Windows XP Tablet PC"

http://support.microsoft.com/kb/898630

Something I would add to that article is that if you do use Propagate Labels on a Tablet, the table uses to do the layout quickly becomes corrupted and you may find that Word crashes. In my experience, you should avoid Propagate Fields on a Tablet with Windows XP SP2. If you do use it by accident, I suggest you use Word's Undo feature to undo the attempted Propagate, immediately. I have generally found that the corruption is undone or does not occur in that case.

This article also contains two Word VBA macros to do the propagation.

The first was written by Microsoft Word MVP Doug Robbins (I've made two minor changes to his code). The second was based on his code and was written by me.

Surely replicating label contents should be really easy? Each label is just a cell in a table so all you need to do is copy the contents of cell 1 to all the other cells and insert a { NEXT } field, right?

Well, not quite, because some Label layouts have "spacer" columns between each pair of "label" columns. For example, the layout for Avery A4/A5 label type J8651 has 65 labels arranged in 13 rows of 5 columns. But the layout generated by Word contains 9 columns - e.g. the first row is as follows:

 

 

 

«Next Record»

 

 

«Next Record»

 

 

«Next Record»

 

 

 «Next Record»

 

 

In this case a macro obviously needs to skip the narrow "spacer" columns and only copy the contents of cell 1 to the odd-numbered columns.

 

How does Word tell whether it needs to skip columns in some layouts but not others?

 

Well, I don't know exactly, but I believe Word looks at the widths of the columns. If it discovers that the odd-numbered columns 1,3,5 etc. are all the same width X and the even-numbered columns all have the a different width Y, and X is not the same as Y, it skips columns. Otherwise, it copies the contents to every cell. (I don't think that is the whole story but it is the theory that macro 2 relies on)

 

Macro 1 (by Doug) does not rely on that. It assumes you have created your label layout in the usual way and have left  { NEXT } fields («Next Record» fields) as Word has inserted them, i.e. in "label" cells but not "spacer" cells. The macro

 - adds a «Next Record» field to the beginning of cell 1

 - copies the content of cell 1

 - pastes the copy into every table cell that already contains at least one field

 - removes the «Next Record» field from the beginning of cell 1

 

If you are not used to working with macros, see the following article for information on how to install and run these macros:

 

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

 

Macro 1

 

Sub MailMergePropagateLabel()

Dim atable As Table
Dim i As Long, j As Long
Dim source As Cell, target As Cell
Dim myrange As Range
Set atable = ActiveDocument.Tables(1)
Set source = atable.Cell(1, 1)
Set myrange = source.Range
myrange.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=myrange, Text:="NEXT", PreserveFormatting:=False
source.Range.Copy
For j = 2 To atable.Columns.Count
  Set target = atable.Cell(1, j)
  If target.Range.Fields.Count > 0 Then
    target.Range.Paste
  End If
Next j
For i = 2 To atable.Rows.Count
  For j = 1 To atable.Columns.Count
    Set target = atable.Cell(i, j)
    If target.Range.Fields.Count > 0 Then
      target.Range.Paste
    End If
  Next j
Next i
atable.Cell(1, 1).Range.Fields(1).Delete

End Sub
 

Macro 2

 

Sub MailMergePropagateLabel2()

Dim atable As Table
Dim i As Long, j As Long
Dim jBlank As Integer
Dim source As Cell
Dim myrange As Range
Set atable = ActiveDocument.Tables(1)
' Are we doing all columns or skipping columns?
' jBlank = 0 means "replicate to odd-numbered columns"
' jBlank = 2 means "replicate to all columns"
jBlank = 2
If atable.Columns.Count > 2 Then
  If atable.Columns.Count Mod 2 = 1 Then
    If atable.Columns(2).Width <> atable.Columns(1).Width Then
      jBlank = 0
      For j = 3 To atable.Columns.Count
        If atable.Columns(j).Width <> atable.Columns(2 - (j Mod 2)).Width Then
          jBlank = 2
          Exit For
        End If
      Next j
    End If
  End If
End If

Set source = atable.Cell(1, 1)
Set myrange = source.Range
myrange.Collapse wdCollapseStart
ActiveDocument.Fields.Add Range:=myrange, Text:="NEXT", preserveformatting:=False
source.Range.Copy
For i = 1 To atable.Rows.Count
  For j = 1 To atable.Columns.Count
    ' skip cell 1
    If i + j > 2 Then

      ' always delete the cell content
      atable.Cell(i, j).Range.Delete

      ' If it's a label, not a spacer, copy the content
      If j Mod 2 <> jBlank Then
        atable.Cell(i, j).Range.Paste
      End If
    End If
  Next j
Next i
atable.Cell(1, 1).Range.Fields(1).Delete

End Sub
 

Google
 

Please post any follow-up questions to this article in the Microsoft public newsgroup on mailmerge and fields. If you are using a newsreader such as Outlook Express, the server is at news://news.microsoft.com and the Mailmerge newsgroup is at news://news.microsoft.com/microsoft.public.word.mailmerge.fields. Otherwise, you can go to the Microsoft Communities home at  http://www.microsoft.com/communities and look for the group. For some reason it is currently named "Mailmerge and Fax"
Disclaimer

Peter Jamieson's Tip Pages: Copyright © 2005-2007, Peter Jamieson

Terms of Use