>In the Visual FoxPro code, I have:
>
>
>WITH loWord.oWord.Selection.Find
> ...
> .Text = "[Anschrift1]"
> .Replacement.Text = ALLTRIM(Anschrift1)
> .Execute(wdReplaceAll)
>ENDWITH
>
>loWord is a reference to a class that does some help with Word automation; the oWord object allows me to access the Word object model.
>
>The idea is to have standard texts as "markers" where variable texts should be replaced.
>
>Before executing the .Execute(wdReplaceAll), that actually does the replacing, .Text has the specified value. Why would this jump to the value 2 (which happens to be the value of constant wdReplaceAll) as soon as the .Execute(...) is executed? Also, the results indicate that this is what has been replaced. The text "2" was replaced with the replacement text.
Hilmar,
Using word automation you need to give function parameters in their correct positional order. Find.Execute sytax from documentation:
expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)
You are giving the constant value of 2 as FindText parameter. If you ask why it doesn't error or replace with 2, I don't know, that is VBA:)
Here is the correct syntax:
WITH loWord.oWord.Selection.Find
.Execute("[Anschrift1]",,,,,,,,,ALLTRIM(Anschrift1),wdReplaceAll)
endwith
Having said that, I think find and replace is not the way to do what you are trying to do. You can of course do it that way looping all story ranges (selection is somewhat awkward selection < g > for it - but that is what macro recording writes - using story ranges you could extend it to anywhere including headers, footers).
IMHO, instead you can use mergefield fields. That is exactly for what you describe. Alternatively you could use document variables and set their values. Both are much better than find/replace (IMHO) and more logical way to do that.
Cetin