Hello,

I make a fusion of personal fields into Word, with a vb project.
This code make my search and replace :

Public Sub Remplacer_texte(Texte_à_remplacer As Variant,
Texte_de_remplacement As Variant)
With myWordApplication //
instancié à l'init de la classe
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find
.Text = Texte_à_remplacer
.Replacement.Text = Texte_de_remplacement
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Selection.Find.Execute Replace:=wdReplaceAll
End With
End Sub

It's works great !
But if there is a text area, the text into it is not replaced.

The strange thing, is when i do that directly with Word, Word replace the
texte into text areas too.
I maked a macro to see how Word do that, and the code is exactly the same
with my !!!

If somebody can help me ?

tks
Carl

Re: Problem VB/VBA by Jay

Jay
Mon Sep 15 13:52:44 CDT 2003

Hi, Carl,

You're correct, the Find in VBA works only on the main text story, not on
text boxes (or headers, footers, or some other areas of the document). There
is an imperfect workaround, described here:
http://www.mvps.org/word/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word

Carl wrote:
> Hello,
>
> I make a fusion of personal fields into Word, with a vb project.
> This code make my search and replace :
>
> Public Sub Remplacer_texte(Texte_à_remplacer As Variant,
> Texte_de_remplacement As Variant)
> With myWordApplication //
> instancié à l'init de la classe
> .Selection.Find.ClearFormatting
> .Selection.Find.Replacement.ClearFormatting
> With .Selection.Find
> .Text = Texte_à_remplacer
> .Replacement.Text = Texte_de_remplacement
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchKashida = False
> .MatchDiacritics = False
> .MatchAlefHamza = False
> .MatchControl = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> .Selection.Find.Execute Replace:=wdReplaceAll
> End With
> End Sub
>
> It's works great !
> But if there is a text area, the text into it is not replaced.
>
> The strange thing, is when i do that directly with Word, Word replace
> the texte into text areas too.
> I maked a macro to see how Word do that, and the code is exactly the
> same with my !!!
>
> If somebody can help me ?
>
> tks
> Carl



Re: Problem VB/VBA by Carl

Carl
Tue Sep 16 01:06:22 CDT 2003

Thank you very much for this perfect anwser !