'Struggling with the correct Find.Wrap property when using a macro in a specified Range
I'm trying to write a macro that will check for inconsistencies in spelling between UK and US English, using "aging"/"ageing" as an example here, which displays a messagebox if inconsistencies are found. The caveat is it needs to only search for text in the main body of work, i.e., between the words Abstract and References (both in bold, so it only catches when they've been used as headers).
The issue I'm having is with Wrap = wdFindContinue, which seems to be extended the search outside of the range. However if I use Wrap = wdFindStop, it doesn't work at all (and wdFindAsk is inappropriate for the use case).
Can you see any glaring errors in the code below? Cheers
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
