请测试一下如下代码是否可行 Sub correct_err() ' Dim myRange As Range, myErrors As Variant, myerr As Range Dim n As Integer, c As Integer, errtxt As String Set myErrors = ActiveDocument.Range.SpellingErrors n = myErrors.Count For Each myerr In myErrors Set myRange = myerr errtxt = myerr.Text With myRange '先尝试与前一word(可能是空格)合并 While Not (.Words(1).Previous Is Nothing) .SetRange Start:=.Words(1).Previous.Start, End:=.End .Select .Text = Replace(.Text, Chr(32), "") .HighlightColorIndex = wdYellow c = c + 1 '如果仍有错,则与后一word合并 If .SpellingErrors.Count > 0 Then .Select .Text = Replace(.Text, errtxt, Chr(32) & errtxt, 1) .HighlightColorIndex = wdNoHighlight c = c - 1 While Not (.Words(2).Next Is Nothing) .SetRange Start:=.Words(2).Start, End:=.Words(2).Next.End .Select .Text = Replace(.Text, Chr(32), "") .HighlightColorIndex = wdYellow c = c + 1 '如果错误仍未消除,则恢复原样 If .SpellingErrors.Count > 0 Then .Text = Replace(.Text, errtxt, errtxt & Chr(32), 1) .HighlightColorIndex = wdNoHighlight c = c - 1 End If GoTo NF Wend End If GoTo NF Wend End With NF: Next myerr MsgBox "共发现" & n & "个错误,并尝试更正了" & c & "个(突出显示部分)。", vbInformation End Sub
[此贴子已经被作者于2007-3-26 12:57:52编辑过] |