Thanks for the feedback, it's really appreciated!
Thanks for deleting the post in the other thread, I thought I had.
The texte variable is a Range and its content is set from an objDoc.content.
To tell you the truth, I process rtf files generated by DeepL where I correct any remaining punctuation errors. To do this, I process every punctuation mark in the document, checking that non-breaking spaces, single spaces, etc. are correctly placed before or after the punctuation, depending on the context of it. I also correct formatting errors specific to the formatting that must be respected.
The loop here comes from the fact that not all matches were processed. I have the same error whitout le loop
Code:
texte.Find.ClearFormatting
texte.Find.Replacement.ClearFormatting
texte.Find.MatchWildcards = True
texte.Find.Execute findText:="…([A-Za-zÀ-ÖØ-öø-ÿ0-9])", ReplaceWith:="… \1", Replace:=2
It would be easier to do the processing with regular expressions, but the problem was that I was losing the original formatting of the text contained in the rtf. In fact, I used to do this very well with just a few lines of code, but on plain text, my code was like this :
Code:
regex.Pattern = “(…)([A-Za-zÀ-ÖØ-öø-ÿ])”
regex.Global = True
text.Text = regex.Replace(text.Text, “$1 $2”)
Today, to avoid losing the formatting with a regex, I use this type of code, but not everything is processed as I'd like.
Code:
regex.Pattern = “([A-Za-zÀ-ÖØ-öø-ÿ0-9])\.([A-Za-zÀ-ÖØ-öø-ÿ0-9])”
regex.Global = True
If regex.test(texte.Text) Then
Set objMatches = regex.Execute(text.Text)
For Each objMatch In objMatches
With texte.Find
.ClearFormatting: .Replacement.ClearFormatting: .MatchWildcards = False
.Text = objMatch.Value
.Replacement.Text = Left(.Text, 1) & “. “ & Right(.Text, 1)
.Wrap = wdFindContinue: .Execute Replace:=wdReplaceAll
End With
Next
Set objMatches = Nothing
End If
In short, since February 13 or 14, 2025, after updating something, whether it's Windows 11 or Word or some other setting on the PC, I've had to modify some original code.
Have you tried in word itself by doing Ctrl+H, then check wildcards and paste in search field “^0133([A-Za-zÀ-ÖØ-öø-ÿ0-9])” and replace field “... \1” if you get the same error? I've tried on 2 computers for “...Hello” I get “...H ello”.