Dear All,

Mail Merge result is being cut and pasted into Word from another prog. I
need to find target text, which includes a couple of paras., and replace all
instances with a couple of formatted paras.

Have tried using AutoText and got it to find single isntances, but the
replacement text loses format.

Clearly I need some kind of a loop; if it makes life easier, I'd be happy to
get by replacement text into Windows memory using Ctrl-C and then fire up the
macro?

Many thanks in advance

Re: Find text in a mail merge and replace with other text. by Doug

Doug
Thu Mar 30 14:04:33 CST 2006

The loop you would need is something like the following which assumes that
you have the formatted paragraphs selected when you run it:

Dim ReplacementText as Range
Set ReplacementText = Selection.Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="Text to be replaced",
MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Paragraphs(1).Range.FormattedText = ReplacementText
Loop
End With

If you want to delete the initially selected formatted text, att

ReplacementText.Delete

at the end.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Lambs" <Lambs@discussions.microsoft.com> wrote in message
news:ACEC3DCD-EF7D-416B-A066-A10431FB0A59@microsoft.com...
> Dear All,
>
> Mail Merge result is being cut and pasted into Word from another prog. I
> need to find target text, which includes a couple of paras., and replace
> all
> instances with a couple of formatted paras.
>
> Have tried using AutoText and got it to find single isntances, but the
> replacement text loses format.
>
> Clearly I need some kind of a loop; if it makes life easier, I'd be happy
> to
> get by replacement text into Windows memory using Ctrl-C and then fire up
> the
> macro?
>
> Many thanks in advance



Re: Find text in a mail merge and replace with other text. by Lambs

Lambs
Fri Mar 31 10:49:35 CST 2006

Thanks Doug: it's worked well. Just to give you an idea, it's some automated
letters from some financial software, that we have sent to a .pdf print file,
which we have then 'converted' into Word... (97!)

I think that Word is treating separate paras. as separate Text boxes,
because as soon as I move the cursor away from the text, it turns into
'cross-hairs.'

Just out of curiosity, if I change the (1) in your last line before the Loop
command, does that effectively increase the number of paras. replaced?

Thanks again,

"Doug Robbins - Word MVP" wrote:

> The loop you would need is something like the following which assumes that
> you have the formatted paragraphs selected when you run it:
>
> Dim ReplacementText as Range
> Set ReplacementText = Selection.Range
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(FindText:="Text to be replaced",
> MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
> Selection.Paragraphs(1).Range.FormattedText = ReplacementText
> Loop
> End With
>
> If you want to delete the initially selected formatted text, att
>
> ReplacementText.Delete
>
> at the end.
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Lambs" <Lambs@discussions.microsoft.com> wrote in message
> news:ACEC3DCD-EF7D-416B-A066-A10431FB0A59@microsoft.com...
> > Dear All,
> >
> > Mail Merge result is being cut and pasted into Word from another prog. I
> > need to find target text, which includes a couple of paras., and replace
> > all
> > instances with a couple of formatted paras.
> >
> > Have tried using AutoText and got it to find single isntances, but the
> > replacement text loses format.
> >
> > Clearly I need some kind of a loop; if it makes life easier, I'd be happy
> > to
> > get by replacement text into Windows memory using Ctrl-C and then fire up
> > the
> > macro?
> >
> > Many thanks in advance
>
>
>

Re: Find text in a mail merge and replace with other text. by Doug

Doug
Fri Mar 31 12:22:24 CST 2006

Changing the 1 to some other number will most probably cause an error unless
you included a ^p in the middle of the search string so that the selection
spanned more than one paragraph.

To see what I mean, in a document type

=rand()

and then press enter and then search for

dog.^pThe

and you will see that the selection includes the last word of one paragraph
and the first word of the next.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Lambs" <Lambs@discussions.microsoft.com> wrote in message
news:0A79BC9D-52E5-4DB5-BB05-674BA11B7FD2@microsoft.com...
> Thanks Doug: it's worked well. Just to give you an idea, it's some
> automated
> letters from some financial software, that we have sent to a .pdf print
> file,
> which we have then 'converted' into Word... (97!)
>
> I think that Word is treating separate paras. as separate Text boxes,
> because as soon as I move the cursor away from the text, it turns into
> 'cross-hairs.'
>
> Just out of curiosity, if I change the (1) in your last line before the
> Loop
> command, does that effectively increase the number of paras. replaced?
>
> Thanks again,
>
> "Doug Robbins - Word MVP" wrote:
>
>> The loop you would need is something like the following which assumes
>> that
>> you have the formatted paragraphs selected when you run it:
>>
>> Dim ReplacementText as Range
>> Set ReplacementText = Selection.Range
>> Selection.HomeKey wdStory
>> Selection.Find.ClearFormatting
>> With Selection.Find
>> Do While .Execute(FindText:="Text to be replaced",
>> MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
>> Selection.Paragraphs(1).Range.FormattedText = ReplacementText
>> Loop
>> End With
>>
>> If you want to delete the initially selected formatted text, att
>>
>> ReplacementText.Delete
>>
>> at the end.
>>
>>
>> --
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Lambs" <Lambs@discussions.microsoft.com> wrote in message
>> news:ACEC3DCD-EF7D-416B-A066-A10431FB0A59@microsoft.com...
>> > Dear All,
>> >
>> > Mail Merge result is being cut and pasted into Word from another prog.
>> > I
>> > need to find target text, which includes a couple of paras., and
>> > replace
>> > all
>> > instances with a couple of formatted paras.
>> >
>> > Have tried using AutoText and got it to find single isntances, but the
>> > replacement text loses format.
>> >
>> > Clearly I need some kind of a loop; if it makes life easier, I'd be
>> > happy
>> > to
>> > get by replacement text into Windows memory using Ctrl-C and then fire
>> > up
>> > the
>> > macro?
>> >
>> > Many thanks in advance
>>
>>
>>