Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / April 2007

Tip: Looking for answers? Try searching our database.

find and replace in a mergefield

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rinus - 23 Apr 2007 13:07 GMT
I have a mailmergefield in word. if it contains  a special character ( the
'#' in my case) this special character must be replaced by the special
character and some text.

example: mergefield= "piet#jan#klaas"
this must be chenged in "piet puk#jan puk#klaas"

i googled for it but did not find any answer.....
Peter Jamieson - 23 Apr 2007 16:21 GMT
There are three main possibilities:
a. if the data source lets you define a query or view (e.g. if it is
Access), create a query that does the replacement and use that query as your
data source.
b. with some types of data source you can do (a) by specifying the query in
an OpenDataSource command that you issue using Word VBA.
c. merge to a new document, then use Edit|Find/Replace to replace each "#"
by " puk#" in the new document.
However, since that would affect /every/ "#" and not just the ones in the
mergefield you are interested in, you might need to do more than that.

Peter Jamieson

>I have a mailmergefield in word. if it contains  a special character ( the
> '#' in my case) this special character must be replaced by the special
[quoted text clipped - 4 lines]
>
> i googled for it but did not find any answer.....
Rinmus - 24 Apr 2007 07:29 GMT
a no the datasource is a text file
b not possible neither
c it should only be changed in one occurrunce of the mergefield

> There are three main possibilities:
>  a. if the data source lets you define a query or view (e.g. if it is
[quoted text clipped - 21 lines]
>>
>> i googled for it but did not find any answer.....
Peter Jamieson - 24 Apr 2007 08:00 GMT
If you do (c) then you can
1. surround the mergefield by characters that do not appear in your text or
data, e.g.

¬{ MERGEFIELD myfield }¬

2. in the output document, do a find/replace using wildcards, replacing

(¬*)(#)(*¬)

by

\1 puk\2 \3

3. Repeat (2) until no replacements are made, then replace ¬ by nothing.

You can do that in VBA if necessary.

There is another approach, which is to use VBA and Word's mailmerge events
to replace the #s by the text you want then insert the result as you merge
each record. If anything, that is the "correct" way to do this, but it's
somewhat harder than using regular VBA so if you want to do it, say so - and
you have to be using Word 2002 or later.

Peter Jamieson

> a no the datasource is a text file
> b not possible neither
[quoted text clipped - 25 lines]
>>>
>>> i googled for it but did not find any answer.....
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.