Spell Check problem

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
I have this code for Spell check, it works fine except when the information inputted in the text box is longer than the textbox can show at once (if that makes sense?). I get a type mismatch error.

The code sends the information to a hidden sheet ("Spelling") runs the spell check and then replaces the text in the textboxes with the corrected text.

Code:
Private Sub cmdSpellCheck_Click()
Dim SpellCheck  As String, _
    SpellCheck1 As String
If (Application.CheckSpelling(txtDetails.Text) = True) And (Application.CheckSpelling(txtOther.Text) = True) Then
MsgBox "Spell check returned no errors"
Else
SpellCheck = txtDetails.Text
SpellCheck1 = txtOther.Text
Application.Worksheets("Spelling").Cells(1, 1).Value = SpellCheck
Application.Worksheets("Spelling").Cells(2, 1).Value = SpellCheck1
'Now Check spelling
Worksheets("Spelling").CheckSpelling AlwaysSuggest:=True
txtDetails.Text = ThisWorkbook.Worksheets("Spelling").Cells(1, 1).Text
txtOther.Text = ThisWorkbook.Worksheets("Spelling").Cells(2, 1).Text
End If
End Sub

Is there anything in my code which I could change, or is it to do with the properties of the multiline textbox?
 
So I sort of have it working, would prefer a more clever way which didn't limit the amount of text which can be entered. But I guess I can just code it up to an unrealistic amount.

Code:
Private Sub cmdSpellCheck_Click()
Dim SpellCheck  As String, _
    SpellCheck1 As String, _
    SpellCheck2 As String
If (Application.CheckSpelling(Left(txtDetails.Text, 200)) = True) And (Application.CheckSpelling(Mid(txtDetails.Text, 201, 200)) = True) _
And (Application.CheckSpelling(txtOther.Text) = True) Then
MsgBox "Spell check returned no errors"
Else
SpellCheck = Left(txtDetails.Text, 200)
SpellCheck1 = txtOther.Text
SpellCheck2 = Mid(txtDetails.Text, 201, 200)
Application.Worksheets("Spelling").Cells(1, 1).Value = SpellCheck
Application.Worksheets("Spelling").Cells(1, 2).Value = SpellCheck2
Application.Worksheets("Spelling").Cells(2, 1).Value = SpellCheck1
'Now Check spelling
Worksheets("Spelling").CheckSpelling AlwaysSuggest:=True
txtDetails.Text = ThisWorkbook.Worksheets("Spelling").Cells(1, 1).Text & ThisWorkbook.Worksheets("Spelling").Cells(1, 2).Text
txtOther.Text = ThisWorkbook.Worksheets("Spelling").Cells(2, 1).Text
MsgBox "Spell Check complete"
End If
End Sub
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
My testing seems to show that Application.CheckSpelling won't take a string longer than 255 characters without reporting a Type Mismatch error, so you probably need to check the length of the text returned first before you pass it to this CheckSpelling function. You could maybe process chunks of the text using the funsction so that you don't exceed the limit.
 
Upvote 0
I posted without seeing your posts #8+.

You could avoid splitting the string on a non space eg by using InstrRev:
Code:
If Len(TextBox1.Text)>255 Then
   myStr1 = Left(TextBox1.Text,InstrRev(TextBox1.Text," ",255))
  myStr2 = Mid(TextBox1.Text, Len(myStr1)+1)
End If
 
Upvote 0
Ah, yeah, I hadn't thought of that problem, and would not have known how to solve it, so thanks
 
Upvote 0
How do I use the InstrRev, along with the Mid function?

At the moment it doesn't split the first 255 characters on a non space, but after that it will do
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top