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