View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default find and replace in a mergefield

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


"Rinmus" wrote in message
...
"Peter Jamieson" wrote in
:

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

"Rinus" wrote in message
...
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.....