genespos
genespos

Reputation: 3311

Find each word marked as error

Is it possible to find words that MS-Word marks as errors?

My goal is to find words containing "è" instead of "é", but to use a macro I need to replace the char only into words marked as error.

I'm working on MS-Word 2013

Upvotes: 0

Views: 109

Answers (1)

jsotola
jsotola

Reputation: 2278

here is some code to get you started. you need to add code that checks for the "bad" letter

' this is just demo code that shows how misspelled words could be replaced

' create document with a few words, one or two misspelled
' then single-step this code using F8 key
' while watching the text in the document


Sub aaaaaa()

    Dim i As Integer
    Dim badChr As String
    Dim badWrd As String

    Dim wrd As Object
    For Each wrd In ActiveDocument.Words

        If wrd.SpellingErrors.Count > 0 Then

            badWrd = wrd.SpellingErrors(1).Text
            Debug.Print badWrd

            wrd.SpellingErrors(1).Text = string(len(badWrd),"x")   ' replace whole word if you like
            wrd.SpellingErrors(1).Text = badWrd                    ' put back original

            For i = 1 To wrd.SpellingErrors(1).Characters.Count    ' loop characters in misspelled word
                badChr = wrd.SpellingErrors(1).Characters(i).Text
                wrd.SpellingErrors(1).Characters(i).Text = "x"     ' replace character
                wrd.SpellingErrors(1).Characters(i).Text = badChr  ' restore character
            Next i
        End If
    Next wrd
End Sub

Upvotes: 1

Related Questions