简体   繁体   中英

Type mismatch in .CheckSpelling in Excel VBA

I'm running the following code on a large data set:

Sub ColorMispelledCells()  
For Each cl In ActiveSheet.UsedRange  
If Not Application.CheckSpelling(Word:=cl.Text) Then _  
cl.Interior.ColorIndex = 28  
Next cl  
End Sub 

It seems to work fine for most of the cells, but a good number of them trigger a Run-time error 13 Type Mismatch. I think the problem is that there are some weird characters in those cells. I tried find/replacing them but they don't seem to be going away. Here is one of the cells:

;In the following passage from Edgar Allan Poe's '~'The Premature Burial,'~' what word provides a clue to determining the meaning of '~'litterateur?'~';\\\\; Among her numerous suitors was Julien Bossuet, a poor litterateur, or journalist of Paris. His talents and general amiability had recommended him to the notice of the heiress, by whom he seems to have been truly beloved... ;

The apostrophes around the ~ characters seem to be non-standard apostrophes, but when I copy it from the cell and find/replace with "", it doesn't go away.

Are these special characters causing the mismatch? If so, is there a way to get around them without stripping the cells of punctuation entirely? We need the text in the cell to be roughly the same as before.

The error is not because of those special characters. It is because of the length of the string that you are passing in cl.text . The limit is 255 characters

Type a very long error free sentence which has more than 255 characters in an Excel cell and you will still get the Type Mismatch error.

This will work ( 255 characters)

This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sent

but this will fail ( 256 characters)

This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sentence This is a simple sente

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM