Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word automation - replacing text
Message
De
13/10/2009 04:15:34
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
12/10/2009 21:26:14
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01429077
Message ID:
01429094
Vues:
107
This message has been marked as the solution to the initial question of the thread.
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform