I use this function to replace some access strings in a text document. This function works very well.
Sub reemplazar(doc As Word.Document, after As String, before As String, replaceall As Boolean)
With doc.Content.Find
.Text = after
.Replacement.Text = before
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
If replaceall Then
.Execute replace:=wdReplaceAll
Else
.Execute replace:=wdReplaceOne
End If
End With
End Sub
But ... I do not know why, if I rewrote the function in this way, it will stop working. There is no error or warning, but no replacement is made.
Sub reemplazar(doc As Word.Document, after As String, before As String, replaceall As Boolean)
doc.Content.Find.Text = after
doc.Content.Find.Replacement.Text = before
With doc.Content.Find
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
If replaceall Then
.Execute replace:=wdReplaceAll
Else
.Execute replace:=wdReplaceOne
End If
End With
End Sub
Can someone explain what the difference is between the two fragments or why the second is not working properly? Thank!
source
share