View Single Post
 
Old 07-16-2023, 11:06 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

vivka,


Your code is better (fixes the problems), but looking at every word regardless if spelled wrong or not, could take a long time in large documents. I mean why back up one word at at time?


Try:


Code:
Sub FindPreviousMisspelledWord()
Dim oRng As Range
  Set oRng = Selection.Range
  With oRng
    While .Start <> 0
      .Collapse 1
      .Start = ActiveDocument.Range.Start
      .MoveStart wdWord, -1
      If .SpellingErrors.Count > 0 Then
        .SpellingErrors(.SpellingErrors.Count).Select
        Exit Sub
      End If
      Wend
  End With
  MsgBox "No misspelled words found."
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote