Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Mail Merge

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-15-2011, 01:17 PM
osucjb osucjb is offline Windows XP Office 2007
Novice
 
Join Date: Dec 2011
Posts: 2
osucjb is on a distinguished road
Default Mail Merge - Trailing Spaces

I am working with a mail merge file, and there are two fields that I need put on the same line. The first one is between 7-10 characters, and the second field is 4 characters. If the first field is less than 10 characters, it needs to have spaces filling the rest. I have tried to write a macro to put the trailing spaces in the field before it is merged but it took off the spaces. Is there a good way to do this?
Reply With Quote
  #2  
Old 12-16-2011, 06:31 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,353
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Hi osucjb,

Is there a reason you can't separate the two fields with a right-aligned tab attached to the second field?
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 12-16-2011, 07:27 AM
osucjb osucjb is offline Windows XP Office 2007
Novice
 
Join Date: Dec 2011
Posts: 2
osucjb is on a distinguished road
Default

Yes, These fields are converted to a barcode that is read by a barcode scanner so they have to be spaces if the field is not long enough.
Reply With Quote
  #4  
Old 12-16-2011, 08:18 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,353
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

In that case, you can use a series of tests, coded like:
Code:
{QUOTE "{MERGEFIELD Part_One}{IF{MERGEFIELD Part_One} = "???????" "   "}{IF{MERGEFIELD Part_One} = "????????" "  "}{IF{MERGEFIELD Part_One} = "?????????" " "}{MERGEFIELD Part_Two}" \* CHARFORMAT}
where Part_One is the name of your variable-length mergefield and Part_Two is the name of your fixed-length mergefield. Basically, the IF tests (the parts coded like {IF{MERGEFIELD Part_One} = "?" " "}) evaluate the length of the Part_One field and, according to that length, pad it out to 10 characters. The above coding representations cover from 7 to 9 characters in the Part_One data.

Note that the field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.

Strictly speaking, the QUOTE field isn't necessary but, when used with the CHARFORMAT, means you need only apply your barcode font to the 'Q' in 'QUOTE' for the whole field to be barcoded. That'll make it easier to maintain later on.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 10-26-2016, 11:00 AM
Trailblazer Trailblazer is offline Windows 10 Office 2016
Novice
 
Join Date: Oct 2016
Posts: 2
Trailblazer is on a distinguished road
Default

I'm after something similar. We are sending output from a merge to a virtual printer which takes the output and puts it into our electronic document imaging system.

While the actual printout and print-to-PDF options work just fine, when sent to the generic/text only printer the table is converted to text, which is expected, but unless each column has the same number of spaces the alignment is messed up.

In other software like Excel this is easy to fix; I would change the field to be something like:

Code:
mergefield + space(80-len(field))

currently it looks like this:
Column1              Column2            Column3
Item1 desc           $1234                $123
Item2 description       $2341               $234
Item3              $4567         $456
I can't use len unfortunately. Another possible issue is that the mergefield is actually a collection of items separated with a CR/LF.

For example, <<item>> the merge field, when populated, looks like this:

Item Line1 CR/LF
Item Line2 with more info CR/LF
Item Line 3 still different length than Line1 & Line2 CR/LF

I need to add spaces after Line1 & Line2 so they -at least- match the length of Line3 (or some static character length that suits, like 80). Again, this is in order to make Column 2 line up and not be "jagged". I will need to repeat this for the other columns as well.

I don't believe I can have the user change the source data to match my requirements. I'm also fine if this requires some scripting in a macro, I'm just not sure how to get "there" from "here".
Reply With Quote
  #6  
Old 10-28-2016, 12:03 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,353
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

What you're asking for quite simply can't be done with a mailmerge.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
From a beginner: Mail Merge using Windows Mail mhalpern705 Mail Merge 3 12-16-2011 04:58 AM
New to mail merge help please Keith Mail Merge 2 11-03-2011 03:56 AM
Comma style without trailing zeroes but with decimal part Scaffold Excel 3 10-22-2011 11:08 PM
Saving INDV mail merges During the mail merge sedain121 Mail Merge 2 10-04-2011 07:52 PM
Mail Merge help aman Mail Merge 0 05-07-2010 03:38 AM


All times are GMT -7. The time now is 02:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft