Can I truncate merged text - eg using Left, Right, etc?

J

James

Hi - My mergefield returns a string whicih is a random number from 1 to a
million but with four characters at the end. Eg 12345.fed or 1.fed, etc. I'd
like to remove the .fed suffix and just display the numbered portion of the
mergefield. Can i do this?
Many thanks
James
 
D

Doug Robbins - Word MVP

The best place to manipulate data is in the data source.

You cannot use Left, Right etc. in a merge field and there is no formatting
switch that can be used to cause only the numerals to be displayed.

The only possible way of doing it is if you have the data being inserted
into the cells of table and have the paragraph containing the mergefield
right aligned with a negative right indent in the paragraph definition that
causes the unwanted part of the data to "disappear" out the right-hand side
of the cell.

Of course, after executing the merge, you could use Edit>Replace to replace
the unwanted part of the data with nothing.

--
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
 
P

Peter Jamieson

You may be able to use a numeric format switch to do this - e.g. instead of

{ MERGEFIELD myfield }

use

{ MERGEFIELD myfield \#0 }

(You can Alt-f9 to show the field codes).

It works in simple cases but you need to test with your own data.

Other than that, there are no "right" "left" type functions in the Word
field "language" but if you use VBA to open the data source you can issue
SQL that uses "left", "right" type functions if they are supported by the
data source (e.g. it is possible if your data comes from Access but not if
it is coming from Word), and it is sometimes possible to use a DATABASE
field to do something similar.

Peter Jamieson
 
J

James

Unfortnately I cant get at the data source as it comes from a 3rd party
application and we can't run macros either (for "security" reasons).
Nevertheless, your main suggestion re aligning table cells works perfectly!
I'm very grateful.
Thanks
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top