在CheckSpelling函数中键入不匹配

时间:2016-02-15 17:51:07

标签: vba excel-vba excel

尝试使用

突出显示其中存在语法错误的单元格
Sub ColorMispelledCells()

For Each cl In ActiveSheet.Range("E2:E7199")

**If Not Application.CheckSpelling(Word:=cl.Value) Then _**

cl.Interior.ColorIndex = 28

End If

Next cl

End Sub

由于某些原因在星号中突出显示的行因“类型错误”

而无法编译

1 个答案:

答案 0 :(得分:0)

这似乎有效:

Sub ColorMispelledCells()
    Dim Ap As Object, c As String
    Set Ap = CreateObject("Excel.Application")
    Dim cl As Range, boo As Boolean

    For Each cl In ActiveSheet.Range("E2:E7199")
        c = cl.Text
        If Not Ap.CheckSpelling(c) Then
            cl.Interior.ColorIndex = 28
        End If
    Next cl
    Set Ap = Nothing
End Sub