Help with spellcheck of form fields

H

hlngus

I'm wanting to replace the incorrectly spelled user-input text box
value
with Word's suggested item that is chosen. Using the following code,
the replacement is recognized, but how does one make it update the text
box,
instead of just the active doc?

Private Sub startit()
Load UserForm1
UserForm1.Show
End Sub

' UserForm1 code
Private Sub CommandButton1_Click()

Dim focus As Integer
Dim errorstr As String

With ActiveDocument
If .ProtectionType <> wdNoProtection Then .Unprotect
.Range.LanguageID = wdEnglishUS
.Range.NoProofing = False
If Options.CheckGrammarWithSpelling = True Then
.CheckGrammar
Else
.CheckSpelling
End If
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With

ActiveDocument.Unprotect

Selection.Text = UserForm1.TextBox1.Value

Selection.Range.CheckSpelling IgnoreUppercase:=False, _
customdictionary:="c:\city.dic"

errorstr = Word.Application.CheckSpelling(Word:=Selection.Text)

'
If errorstr = True Then
MsgBox "selection has no spelling errors: "
Else
MsgBox "There are spelling errors: "
focus = 1: GoTo set_focus
End If

Unload Me
Exit Sub

set_focus:
Select Case focus
Case 1: Me.TextBox1.SetFocus
End Select

End Sub


I'm sure it's something simple that is overlooked. Using Word 2000
(9.0.6926 SP-3)
and Windows 2000 (ver 5.0 build 2195 SP-4). Thanks!
 
H

hlngus

Does this also apply to a pop-up form that is called by the active
doc?

I apologize for not making this clear.
 
D

Doug Robbins - Word MVP

See the thread that was started on 1/23/2007 by Fuzzhead with the Subject
"Spell checking" in the microsoft.public.word.vba.general newsgroup.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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