eliminate trailing spaces on a mail merge field

D

DaveS

How can I eliminate trailing spaces on an individual merge field?

The mail merge data source is a mainframe-generated semi-colon
delimited .txt file (Excel/Access formatting is not an option)
where the fields are all a fixed-length, but the values are not always
the maximum field length. (text qualifiers such as " are not used).
I want to eliminate these spaces in the letter text.

Ex. CALL TIME field has a physical length of 20 positions, but may have
the values DURING THE DAY or AT NIGHT
 
G

Graham Mayor

Word does not have a function to use only part of a field. The only
practical way I can see to do this is to edit the data file to remove the
extra spaces. The following macro will remove all the extra spaces from a
semicolon delimited text file

Sub StripSpacesFromData()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "[ ]@([;^13])"
.Replacement.Text = "\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute replace:=wdReplaceAll
End With
End Sub

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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