【发布时间】:2022-06-30 05:42:40
【问题描述】:
我正在尝试检查英国和美国英语之间的拼写不一致,例如“aging”/“ageing”,如果发现不一致,则显示一个消息框。
我只需要在工作主体中搜索文本,即在“摘要”和“参考”这两个词之间(都是粗体,所以它只在用作标题时才被捕获)。
Wrap = wdFindContinue 似乎将搜索范围扩展到了范围之外。Wrap = wdFindStop 不起作用。wdFindAsk 不适合用例。
Sub inconsistencyCheck()
Dim myrange As Range
Dim a As Integer
Dim b As Integer
Set myrange = ActiveDocument.Range
a = 0
b = 0
'search for abstract
With Selection.Find
.Font.Bold = True
.Text = "Abstract"
.Wrap = wdFindContinue
.Execute
End With
myrange.Start = Selection.Start
'search for references
With Selection.Find
.Font.Bold = True
.Text = "References"
.Wrap = wdFindContinue
.Execute
End With
myrange.End = Selection.Start
myrange.Select
'search for inconsistencies
With myrange.Find
.MatchWholeWord = False
.Wrap = wdFindContinue
.Execute findtext:="aging"
.Format = True
.Forward = True
If .Found = True Then
a = 1
End If
.MatchWholeWord = False
.Wrap = wdFindContinue
.Execute findtext:="ageing"
.Format = True
.Forward = True
If .Found = True Then
b = 1
End If
End With
If a = 1 And b = 1 Then
MsgBox "Both spellings of ageing found, please revise"
End If
End Sub
【问题讨论】: