Spell checking a TextBox

  • Thread starter Patrick C. Simonds
  • Start date
P

Patrick C. Simonds

Is there any way to spell check the text in a UserForm TextBox when the user
exits the TextBox?
 
M

Mike H

Hi,

I'll be really interested to see if anyone solves this within a textbox and
correct words. You can check the spelling like this but it doesn't correctt

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim word As Variant
For Each word In Split(TextBox1.Text)
If Not Application.CheckSpelling(word) Then
MsgBox word & " isn't a valid word."
End If
Next word
End Sub

Mike
 
M

Mike H

Hmmm.

A slight change to stop it apellchecking the whole sheet

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim DummyCell As Range
Set DummyCell = Range("IV65536")
Sheets("Sheet1").Range("a1").Value = TextBox1.Text
Application.EnableEvents = False
Union(DummyCell, Sheets("Sheet1").Range("a1")).CheckSpelling
Application.EnableEvents = True
TextBox1.Text = ""
TextBox1.Text = Sheets("Sheet1").Range("a1").Value
Sheets("Sheet1").Range("a1").Value = ""
End Sub

Mike
 
J

john

Simplest way would be to use a worksheet to pass your textbox value to -
spellcheck & then return corrected text back to textbox.

Something like following may work:

Private Sub CommandButton1_Click()
' use Sheet Range A1 to spell check text
With Sheets("Sheet1").Range("A1")

.Value = TextBox1.Text

.CheckSpelling

TextBox1.Text = .Text

.Value = ""

End With


End Sub
 
M

Mike H

Hi,

Here's a cheating way of doing it which corrects the text

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Sheets("Sheet1").Range("a1").Value = TextBox1.Text
Application.EnableEvents = False
Sheets("Sheet1").Range("a1").CheckSpelling
Application.EnableEvents = True
TextBox1.Text = ""
TextBox1.Text = Sheets("Sheet1").Range("a1").Value
Sheets("Sheet1").Range("a1").Value = ""
End Sub


Mike
 
P

Patrick C. Simonds

Mike, Thanks for your time.

My problem now is that spell checker does not spell check what is pasted to
cell A1.

It is an interesting thing, I disabled the line which removes the text from
cell A1 at the end of the routine, and then I tried running spell check on
the sheet and spell check still did not see the spelling errors in the text.
I used this code because it checks the entire sheet so I placed some miss
spelled words in another cell and spell checker did find those misspellings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top