I want to replace all threeletter words with new string. MsgBox display variable threeLetterWord has new value, but text not change.
Sub ShowThreeLetterWords()
Set threeLetterRegExp = New RegExp
threeLetterRegExp.Pattern = "\b[a-zA-Z]{3}\b"
threeLetterRegExp.Global = True
Dim threeLetterWords As MatchCollection
Set threeLetterWords = threeLetterRegExp.Execute(ActiveDocument.Range)
For Each threeLetterWord In threeLetterWords
threeLetterWord = threeLetterRegExp.Replace(threeLetterWord, "sasa")
MsgBox threeLetterWord
Next threeLetterWord
End Sub
The regular expression is fine. I think the only problem is that you should not assign again treeLetterWord in a loop, since it’s a “foreach iteration varible”.
Directly
Should be OK