View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Unable to update labels in mail merge

What are the exact steps to make this a template?

Create a new document, use VBE to create a new module in that document,
put the Sub in there, use File-Save As or Office Btton-Save As to save
as a template (.dot in Word 2003 and earlier, .dotm in Word 2007).


You say the template goes in the startup folder. Which is the Word

startup
folder? Is it C:\Program Files (x86)\Microsoft Office\Office12, or in
C:\Program Files (x86)\Microsoft Office\Templates, or somewhere else?


In Word 2007, the Startup folder is defined in Word Office Button-Word
options-Advanced-File Locations

In Word 2003 (and probably earlier) it's in Word Tools-Options-File
Locations.

Here, for example, these are both set by default to be in per-user
locations.

There is also a startup folder under the program path, but AIUI this is
the "Wrong" path to put things - see e.g.

http://word.mvps.org/faqs/macrosvba/...orrectPath.htm

I expect Doug will tell us if this is no longer correct.

Does the name of the template file matter?


It shouldn't.

Or does the first line "Sub
MailMergePropagateLabel()" do the mapping over the bad default command
regardless of the template name?


It should, but if the macro is not running at all it is possible that
there is a security/trust issue.

I've tried several incatations of the template file, but I am still not
getting the Address Block propogating properly across the label

document
after hitting "Update Labels".


If your label layout happens to be the sort which uses "spacer" columns
then the macro will need to skip some cells. This version may do it.


Sub MailMergePropagateLabel()

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

By the way, I'm not on a tablet PC, but on a touch enabled desktop.

You are
going to see many more people run across this bug as Win7 drives more

touch
PC volume into the market.


FWIW I am not a Microsoft employee, but a few years ago I put a lot of
effort into verifying that this problem was tablet-specific and
reporting it. Since then, the problem has spread to Vista when using
tablet and other types of device. Unfortunately I have no idea whether
Microsoft has actually identified the root cause (I made one
suggestion), but if they have, I really do think this problem deserves a
fix in Windows because it appears that the Word team simply cannot work
around it.

Peter Jamieson

http://tips.pjmsn.me.uk

someotherbob wrote:
What are the exact steps to make this a template?

You say the template goes in the startup folder. Which is the Word startup
folder? Is it C:\Program Files (x86)\Microsoft Office\Office12, or in
C:\Program Files (x86)\Microsoft Office\Templates, or somewhere else?

Does the name of the template file matter? Or does the first line "Sub
MailMergePropagateLabel()" do the mapping over the bad default command
regardless of the template name?

I've tried several incatations of the template file, but I am still not
getting the Address Block propogating properly across the label document
after hitting "Update Labels".

By the way, I'm not on a tablet PC, but on a touch enabled desktop. You are
going to see many more people run across this bug as Win7 drives more touch
PC volume into the market.

Thanks,
Bob




"Doug Robbins - Word MVP on news.microsof" wrote:

Sounds like you might be using a Tablet PC or a PC with some form of Tablet
functionality.

Use the following macro to overcome the problem with propagation of mail
merge field fields with a label type mail merge when using a Tablet PC and
some other Computers that have Tablet PC Functionality available:

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



It is suggested that you put this code into a template that you save in the
Word Startup folder so that it becomes an add-in and will be available
whenever you need it. As the macro has the same name as the Word Command
that is supposed to do the job, this macro will run when the Update Labels
button is used when setting up the mail merge label main document.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"BK" wrote in message
news
I'm using mswordxp. I've inserted my merge field in the first column/row
of
the label template and clicked on the update icon in the tool bar and have
no
response. Shouldn't it update and insert "next record" in every cell?