Personal website of Gregory K. Maxey, Commander USN (Retired)
Do you have ad-blocking software enabled? While I respect your right to do so, your donations and the minimal advertisements on this site help to defray internet and other costs of providing this content. Please consider excluding this website from blocking or turning off the blocker while browsing this site.
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.
If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!
This Microsoft Word Tips & Microsoft Word Help page provides you a method to spell check Userform textbox entries. Since there is no built-in method to check for spelling errors contained in a Userform textbox, whatever the user enters is processed "as is."
If textbox text is transferred to the document with errors, those errors will need to be fixed in the document. In protected documents this presents problems of its own.
Here is a fanciful example of a textbox with plenty of unsightly errors.
Clicking on the "Check Spelling" command button will launch the familiar "Check Spelling" dialog box.
After you have processed each of the identified spelling errors, the corrected text is displayed in the Userform Textbox.
And clicking the "Finished" command button transfers the corrected text to the document.
The process of spell checking a Userform Textbox includes creating a temporary document (a scratchpad). Code contained in a single Command Button in the Userform transfers the Textbox text to the temporary document and the spelling dialog is invoked. Once the errors are corrected, the text is transferred back and displayed in the Textbox. The code used is shown below:
Private Sub cmdCheck_Click() Dim oScratchPad As Word.Document Dim oCtr As Control Dim oRng As Word.Range Dim bChecked As Boolean 'Open a new document to serve as a scratchpad If oScratchPad Is Nothing Then Set oScratchPad = Documents.Add(Visible:=False) oScratchPad.Windows.Add oScratchPad.Windows(2).Visible = False Else oScratchPad.Range.Delete End If Set oScratchPad = Documents.Add 'Iterate through all Userform Controls For Each oCtr In Me.Controls 'Process TextBox Controls If TypeOf oCtr Is MSForms.TextBox Then With oCtr If .Value = "" Then bChecked = True Else Set oRng = oScratchPad.Range 'Write the TextBox content to the scratchpad oRng = .Value 'Check and correct spelling errors With oRng With Dialogs(wdDialogToolsSpellingAndGrammar) 'If user cancels If .Show = 0 Then bChecked = False Exit For End If End With 'Clip the end of document marker .End = .End - 1 End With bChecked = True 'Write the corrected text to the TextBox .Value = oRng.Text End If End With End If Next oCtr Set oCtr = Nothing oScratchPad.Close wdDoNotSaveChanges Set oScratchPad = Nothing If bChecked Then MsgBox "Check complete" Else MsgBox "Spell checking was stopped in process." End If lbl_Exit: Exit Sub End Sub
See: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.
That's it! I hope you have found this tips page useful and informative. You can download the demonstration documents used to create this tips page: Spell Check Userform Text
Do you want to make a payment for consulting work or donate to help support this site?
PayPal is a safe, easy way to pay online.
Use the appropriate currency "Donate" button to make a payment or donation.