Probleme d'adaptation de recherche/remplacement OleWord
Je cherche le moyen de rechercher et remplacer une chaine de caractere je reussi a selectionner la chaine mais pas a la remplacer.
le code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleFunction("ClearFormatting");
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Replacement").OleFunction("ClearFormatting");
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Text", "toto"); // texte que l'on veut remplacer
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Replacement").OlePropertySet("Text", "tata"); // texte qui va remplacer
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Forward",true);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Wrap", 1);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("Format", false);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchCase", false);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchWholeWord", false);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchWildcards", false);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchSoundsLike", false);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertySet("MatchAllWordForms", false);
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OleProcedure("Execute"); |
La chaine recherchee "toto" est selectionnee.
Si je modifie la derniere ligne comme suit j'ai une erreur nom inconnu.
Code:
1 2
|
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Find").OlePropertyGet("Execute").OleProcedure("Replace", 2); |
le code en VB:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "toto"
.Replacement.Text = "tata"
.Forward = True
.Wrap = wdFindContinue ' = 1
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll ' = 2 |
Ca fait plusieurs jours que j'y suis et je n'y arrive pas, si quelqu'un a une idee? elle sera bien venue.