Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba CheckSpelling函数中的类型不匹配_Vba_Excel - Fatal编程技术网

Vba CheckSpelling函数中的类型不匹配

Vba CheckSpelling函数中的类型不匹配,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 由于某种原因,以星号突出显示的行无法编译,因为“类型错误”这似乎有效: Sub ColorMispelledCe

尝试使用

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
由于某种原因,以星号突出显示的行无法编译,因为“类型错误”

这似乎有效:

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

我没有发现任何错误。我必须将cl
Dim cl声明为Variant
您也可以将其声明为
Dim cl As Range
我正在excel 2016上运行它,也许这就是问题所在?我安装了excel 2016,它在那里也可以正常工作。如果不是Ap.CheckSpelling(c),那么-似乎会触发相同的错误