This needs to go in the code sheet for the userform
Private Sub cmdSpellXtra_Click()
If IsSpellingCorrect(TextBox1.Text) Then
cmdSpellXtra.BackColor = &HFF00&
Else
cmdSpellXtra.BackColor = &HFF&
strSpellCheckXtra = TextBox1.Text
ThisWorkbook.Worksheets("SpellCheck").Cells(1, 1).Value = strSpellCheckXtra
'Now Check spelling
ThisWorkbook.Worksheets("SpellCheck").Cells(1, 1).CheckSpelling AlwaysSuggest:=True
TextBox1.Text = ThisWorkbook.Worksheets("SpellCheck").Cells(1, 1).Text
cmdSpellXtra.BackColor = &HFF00&
End If
End Sub
also this code needs to go in the same module
Function IsSpellingCorrect(ByVal sInput As String) As Boolean
Dim i As Long
Dim lLength As Long
Dim lWordLen As Long
Dim sTmp As String
Dim bSpellingOK As Boolean
Dim vWords As Variant
Dim sArr() As String
Dim iCount As Integer
If Len(sInput) < 256 Then
IsSpellingCorrect = Application.CheckSpelling(sInput)
Exit Function
End If
vWords = Split(sInput, Chr(32), -1, vbBinaryCompare)
sTmp = ""
lLength = 0
iCount = 0
For i = LBound(vWords) To UBound(vWords)
lWordLen = Len(vWords(i))
If lLength + lWordLen < 256 Then
sTmp = sTmp & vWords(i) & " "
Else
iCount = iCount + 1
ReDim Preserve sArr(1 To iCount)
sArr(iCount) = sTmp
sTmp = ""
End If
lLength = Len(sTmp)
Next i
If lLength > 0 Then
iCount = iCount + 1
ReDim Preserve sArr(1 To iCount)
sArr(iCount) = sTmp
End If
For i = 1 To iCount
bSpellingOK = Application.CheckSpelling(sArr(i))
If Not bSpellingOK Then Exit For
Next i
IsSpellingCorrect = bSpellingOK
End Function
you might find you have to change the name of the textbox and your command button click, this code also relies on you having a hidden worksheet called "SpellCheck".
The code isn't mine just one i've adapted from the net!
Regards,
Simon
Bookmarks