• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2801
  • Last Modified:

Spell Check a Textbox in Excel VBA

Hello

How Can I Spell Check a Users input into a Textbox on a Userform?
This is in EXCEL.

Thanks
0
p-plater
Asked:
p-plater
  • 3
  • 2
  • 2
  • +1
3 Solutions
 
dlmilleCommented:
0
 
CowboyJeeperCommented:
quick and dirty method
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Range("A1") = TextBox1.Text
    Range("A1").CheckSpelling
    TextBox1.Text = Range("A1")
End Sub

Open in new window

0
 
kgerbChief EngineerCommented:
On way to do it is to send the text box value to a cell and then check the spelling on the cell like this.
Private Sub CommandButton1_Click()
With Range("A1")
    .Value = Me.TextBox1
    .CheckSpelling
    Me.TextBox1 = .Value
End With
End Sub

Open in new window

See attached workbook for example.

Kyle
Q-27415164-RevA.xlsm
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
dlmilleCommented:
Better yet - we can create a temporary worksheet and populate cell A1 with the contents of the textbox value, then we can use the .CheckSpelling method on the range A1.

We can keep the temporary sheet hidden during the process, and delete it when we're done, after having copied the revised "checked" contents of Cell A1 back to the Textbox.

Here's the primary code:
Private Sub CommandButton1_Click()
Dim wks As Worksheet
Dim wkb As Workbook
Dim oldActiveSheet As Worksheet

    Set oldActiveSheet = ActiveSheet
    
    Set wkb = ActiveWorkbook
    Set wks = wkb.Worksheets.Add
    wks.Name = "temp_spell"
    wks.Visible = xlSheetHidden
    
    wks.Range("A1").Value = TextBox1.Value
    
    wks.Range("A1").CheckSpelling
    
    TextBox1.Value = wks.Range("A1").Value
    
    Application.DisplayAlerts = False
    wks.Delete
    oldActiveSheet.Activate
End Sub

Open in new window


See attached demo workbook with simple userform to demonstrate the process.

This should work as long as the text box contents don't exceed what one cell can hold.  Otherwise, a creative alternative on multiple cells would need to be built - doable, but perhaps not necessary for your needs.

Let me know how this works for you!

Enjoy!

Dave
checkSpellUserForm-r1.xls
0
 
kgerbChief EngineerCommented:
...damn over-achievers :)
0
 
p-platerAuthor Commented:
Thanks
A Further Question as this will be used over multiple machines is there anyway to have a custom dictionary in the excel addin - Or add words to the dictionary via VBA then remove them when the spellcheck is finished?

There are a number of common things like bx (Box), rl (Roll) that I need to exclude from being checked.
0
 
dlmilleCommented:
Probably - I'll take a look - but this seems like a scope for a new question - especially as its focused on having a common dictionary where we can get some other E-E experts in to help with that focused question.

Dave
0
 
p-platerAuthor Commented:
Changing last comment to a new question
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now