Solved: Problem with GoToNext(what:=wdGoToSpellingError)
I am using Word 2003 for this problem. I have not tried with earlier versions.
Using the code below, where rngError is of type Word.Range, strError is of type string and lngLastStart is of type Long, I find that the GoToNext fails when there is punctuation (e.g., comma, period, or slash) immediately after the spelling error.
In that case, one of two things happens:
1. If the spelling error is the first word in the document, that spelling error is found, but no others are found.
2. If the spelling error is not the first word in the document, then all spelling errors up to, but not including that error, are found, and no errors after that spelling error are found.
I did not find anything in the MSFT KB on this issue.
The same problem occurs if I use GoToNext with the Range object, instead of the Selection object.
The problem does not occur using the ProofReadingErrors collection, only when navigating with GoToNext(what:=wdGoToSpellingError).
Any ideas on a workaround, without using the ProofReadingErrors collection?
[vba]
lngLastStart = -1
Do
Set rngError = Selection.GoToNext(what:=wdGoToSpellingError)
With rngError
If .Start = lngLastStart Then
Exit Do
End If
strError = .Text
lngLastStart = .Start
.Collapse direction:=wdCollapseEnd
.Select
End With
Loop
[/vba]