View Single Post
 
Old 07-16-2023, 11:14 AM
puff puff is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
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

Thank you so much! And yes, yours run faster.
Reply With Quote