Spell Check within a cell and change color of misspelled words to red

Viewed 5272

I'm working on an automation, where i need to do spell check a paragraph within a cell and highlight error words in red, and this spell check i need to do in column which will have dynamic range.

I'm using the below code

Sub spellcheck()

    Dim intOffsetCol As Integer
    Dim intChrCnt As Integer
    Dim varTempString As Variant

    intOffsetCol = 1

        For intChrCnt = 1 To Trim(Len(ActiveCell.Value)) Step 1 'Left to right
            'A space character is represented by an ASCII code of 32.
            If Asc(Mid(ActiveCell.Value, intChrCnt, 1)) <> 32 Then
                varTempString = varTempString & Mid(ActiveCell.Value, intChrCnt, 1)
            Else


                If Not Application.CheckSpelling(Word:=varTempString) Then
                varTempString.Interior.ColorIndex = 52

                varTempString = ""
                intOffsetCol = intOffsetCol + 1
                End If
            End If
        Next intChrCnt

        If varTempString <> "" Then
            If Not Application.CheckSpelling(Word:=varTempString) Then varTempString.Interior.ColorIndex = vbRed

        End If

End Sub

And I'm getting "Run time error 424" on varTempString.Interior.ColorIndex = 52

Why am I getting an error on that line?

1 Answers
Related