Trim spaces from a mail merged field in Word 2007

Posted on 2015-02-20
Last Modified: 2016-02-11
I am building mail merged letters in Word 2007 from a .csv file.  I am exporting the file from a 3rd party application so do not have the ability to trim the field prior to the .csv file creation.  Is there a way in Word 2007 to trim a field that has spaces that need to be removed. (ex. Company Name field has the potential for a lot of trailing spaces.)
Is there a way to insert a space into a field after a Semicolon? (ex. Address field that has the Street, City, State and Zip as one field with no spaces following the semicolons)
Question by:PJ_KD
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 250 total points
ID: 40621559
Use the Find and Replace function (Ctrl+H).
1. Find: two spaces.
Replace: one space.
Repeat several time.
2. Find: semicolon
Replace: semicolon and space.
Then repeat number 1.

Author Comment

ID: 40621576
Is there no automated means to do this like the trim function in Excel?
LVL 24

Expert Comment

by:Phillip Burton
ID: 40621581
Only through a macro. But it only takes about 1 minute to do the above.
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

LVL 76

Accepted Solution

GrahamSkan earned 250 total points
ID: 40621587
We are generally reliant on Word Field operations during a mail merge and that doesn't provide a way of editing part of a field. It could be done with VBA, but it would be better to do it before presenting the file to the merge.

If you can use the file as an input to the mail merge, you should be able to input it to some other process, edit it, and present the result to the merge.

Excel can open .csv files, so that would be the best. Word can open .csv files and the text can then be converted into tables for mail merge input, but the process gets tricky if there are embedded separator characters (commas) in the fields.

Author Closing Comment

ID: 40626529
I appreciate the input from  you both.  I was really hoping for an automated solution, if that was possible since there will be many letters occurring for the foreseeable  future.  I revised the mail merge main document so that the deletion of the spaces will not be an issue.
LVL 76

Expert Comment

ID: 40626880
You could use VBA to automate the procedure thus:

1. Read the supplied file line, by line
2. Do the required modifications and output to another file (both spaces and semi-colon)
3, Run the mail merge with the revised file as input.

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question