Re: Replace words with corresponding mergefields by Doug
Doug
Sat Jul 03 20:15:28 CDT 2004
Hi Florian,
The following code should do what you want:
' Macro created 19/7/00 by Doug Robbins
'
Dim tag As Range, fname As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\@\@*\@\@", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set tag = Selection.Range
Set fname = Selection.Range.Duplicate
fname.End = fname.End - 2
fname.Start = fname.Start + 2
ActiveDocument.Fields.Add Range:=tag, Type:=wdFieldEmpty,
Text:="mergefield " & fname
Loop
End With
--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.
Hope this helps,
Doug Robbins - Word MVP
"F. Roettger" <froettger@web.de> wrote in message
news:Xns9518AD0E194EDfroettgerwebde@62.153.159.134...
> Hi all,
>
> I want to replace words like @@WORD@@ to the corresponding mergefield. The
> words are placeholders in a comment and after connecting to the datasource
> I want them to be replaced.
>
> Hope somebody can help.
>
> Thanks in advance.
> Florian