Application.CheckSpelling在> 255个字符的单元格上失败

我正在尝试编写一个macros来突出显示e5:e20000范围内有拼写错误的单元格。 每当我点击一个超过255个字符的单元格时,我会得到一个“运行时错误113”。 我试着添加一个条件来跳过+255个字符单元格,但实际上并不工作。

理想情况下,我想包括所有的单元格,而不pipe字符数量。 有什么build议? 谢谢!

Sub Cellswithtypos() For Each cl In ActiveSheet.UsedRange.Range("E5:E20000").Cells If Len(cl.Value) <= 255 And Not Application.CheckSpelling(Word:=cl.Text) Then _ cl.Interior.ColorIndex = 18 Next cl End Sub 

您必须先嵌套检查单元格的长度。 我还添加了空白单元格检查,以便您可以绕过空白(应该加速代码)。

 Sub Cellswithtypos() For Each cl In ActiveSheet.UsedRange.Range("E5:E20000").Cells If Len(cl.Value) <= 255 And Len(cl.Value) > 0 Then If Not Application.CheckSpelling(Word:=cl.Text) Then cl.Interior.ColorIndex = 18 End If End If Next cl End Sub