Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[VBA] Problème avec replacement

1 réponse
Avatar
HD
Bonjour,

J'ai un petit souci avec ma macro VBA... Le texte recherché est bien trouvé,
il est sélectionné mais par contre il n'est pas remplacé par mon texte de
remplacement... Avez vous une idée de ce qui pourrait coincé ?
Vous en remerciant d'avance.
Voici mon code :

Dim AppWord As Object, DocWord As Object
Set AppWord = CreateObject("Word.Application")
AppWord.ShowMe
AppWord.Visible = True
Set DocWord = AppWord.Documents.Open(CheminW, ReadOnly:=False)

With AppWord.Selection
.wholestory
.Find.ClearFormatting
.Find.Replacement.ClearFormatting
With .Find
.Text = "[PRODVEGER]"
.Replacement.Text = "TTTTESSTTTTTTTTTT"
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Wrap = wdFindContinue
End With
.Find.Execute Replace:=wdReplaceAll
End With

--
@+
HD

1 réponse

Avatar
Gérard GODIN
Le 19/04/2011 14:07, HD a écrit :
Bonjour,

J'ai un petit souci avec ma macro VBA... Le texte recherché est bien trouvé,
il est sélectionné mais par contre il n'est pas remplacé par mon texte de
remplacement... Avez vous une idée de ce qui pourrait coincé ?
Vous en remerciant d'avance.
Voici mon code :

Dim AppWord As Object, DocWord As Object
Set AppWord = CreateObject("Word.Application")
AppWord.ShowMe
AppWord.Visible = True
Set DocWord = AppWord.Documents.Open(CheminW, ReadOnly:úlse)

With AppWord.Selection
.wholestory
.Find.ClearFormatting
.Find.Replacement.ClearFormatting
With .Find
.Text = "[PRODVEGER]"
.Replacement.Text = "TTTTESSTTTTTTTTTT"
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Wrap = wdFindContinue
End With
.Find.Execute Replace:=wdReplaceAll
End With



Bonsoir,

Voulez-vous essayer ceci, une autre manière de faire ?
'adapter le code svp et définir les variables

Pos1 = Selection.End
Selection.MoveDown Unit:=wdLine, Count:=xxxx, Extend:=wdMove
PosDep1 = Selection.End

Set maselection = ActiveDocument.Range(Start:=Pos1, End:=PosDep1)
With maselection.Find
.ClearFormatting
.Text = "."
With .Replacement
.ClearFormatting
.Text = ","
End With
.Execute Replace:=wdReplaceAll, _
Format:=True, MatchCase:=True, _
MatchWholeWord:=True
End With

End Sub

Bonne soirée