Word VBA:我的 Find.Replacement 命令只会找到目标的第一个实例。为什么?它没有继续寻找更多的实例。
我的例程应该找到具有指定样式的所有文本并将其替换为另一种样式。IT 只找到第一个实例。
Function ExecReplaceStyle(strSourceStyle As String, strDestinationStyle As String) As Integer
On Error GoTo ErrorHandler
Dim Rng As Range
Dim ret As Integer
ExecReplaceStyle = 0
Set Rng = docActiveDoc.Range
Rng.Find.ClearFormatting
Rng.Find.Style = ActiveDocument.Styles(strSourceStyle)
Rng.Find.Replacement.ClearFormatting
Rng.Find.Replacement.Style = ActiveDocument.Styles(strDestinationStyle)
With Rng.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Rng.Find.Execute(Replace:=wdReplaceAll)
Rng.Select
Rng.Find.Execute Replace:=wdReplaceAll
ExecReplaceStyle = ret
Exit Function
ErrorHandler:
ExecReplaceStyle = Err.Number
ErrDescription = Err.Description
Resume Next
End Function