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),那么-似乎会触发相同的错误