Can I check the spelling in only one of multiple form fields?

G

Guest

I have found macros that check every form field in the form. I need to check
only one form field because other fields contain info that will always be
incorrectly spelled. Does someone have a macro that will successfully check
the one field based on the bookmark name or any other reference?
 
G

Greg Maxey

You might adapt this to your needs:

Sub CheckMe()
Dim oRng As Word.Range
ActiveDocument.Unprotect
Set oRng = ActiveDocument.FormFields("Your Field BM name").Range
oRng.NoProofing = False
If oRng.SpellingErrors.Count > 0 Then
ActiveDocument.Bookmarks("Your Field BM
Name").Range.Fields(1).Result.Select
MsgBox "Spelling error!"
End If
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub

and run it on exit from the field.
 
G

Guest

Greg,
I tested the macro. I am not sure if it did anything. It did not provide
the message nor did it highlight the misspelled words. The macro below does
the job but checks any text in the document.


Sub FormsSpellCheck()

' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="not2day"
End If

' Set the language for the document.
Selection.WholeStory
Selection.LanguageID = wdEnglishUS

' Perform Spelling/Grammar check.
If Options.CheckGrammarWithSpelling = True Then
ActiveDocument.CheckGrammar
Else
ActiveDocument.CheckSpelling
End If

' ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If

End Sub


If I knew more about VBA I might be able to select only the one field that
needs to be checked.

Aldon
 
G

Greg Maxey

Aldon,

Did you change the index name "Your field BM name" to match the name of
your field?

Try this one:

Sub CheckMeExit()
Dim oRng As Word.Range
ActiveDocument.Unprotect
Set oRng = ActiveDocument.FormFields("Text1").Range
oRng.NoProofing = False
oRng.CheckSpelling
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub

Set the macro to run on exit from a field bookmarked "Text1"
 
G

Guest

Greg,
I tried that and it did not work. I used portions of another macro that I
found and it still does not work. This is what I last used

Sub CheckMeExit()

Dim oRng As Word.Range
ActiveDocument.Unprotect Password:="******"
Set oRng = ActiveDocument.FormFields("underlying").Range
oRng.NoProofing = False
If Options.CheckGrammarWithSpelling = True Then
oRng.CheckGrammar
Else
oRng.CheckSpelling
End If

If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If

End Sub
 
G

Greg Maxey

Aldon,

It worked for me. Here is a modified version of your macro. Make sure
Tools>Options>Check Spelling as you type is set.

Sub CheckMeExit()
Dim oRng As Word.Range
ActiveDocument.Unprotect Password:="******"
Set oRng = ActiveDocument.FormFields("underlying").Range
oRng.NoProofing = False
If Options.CheckSpellingAsYouType = True Then
oRng.CheckSpelling
Else
MsgBox "You don't have your options set to check spelling as you
type."
End If
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub
 
G

Guest

Greg,
Many Thanks, it worked. I have just one additional thing to work out. When
I tab out (exit) the field it takes me back to the first field in the form.
The spelling is checked but I can not figure why it takes me back to that
first field. If you have any suggestions, I would appreciate hearing them.

Aldon
 
G

Guest

Greg,
I appreciate your help greatly. It is listed below for the next person that
needs an answer to the same problem.


Sub CheckMeExit()
Dim oRng As Word.Range
ActiveDocument.Unprotect Password:="060305"
Set oRng = ActiveDocument.FormFields("Text1").Range
oRng.NoProofing = False
If Options.CheckSpellingAsYouType = True Then
oRng.CheckSpelling
Else
MsgBox "You don't have your options set to check spelling as you type."
End If
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
ActiveDocument.Bookmarks("Text2").Range.Fields(1).Result.Select
End Sub
 
G

Greg Maxey

You are welcome. I see that you solved your second question. Sorry I
didn't get back to your earlier. I assume that your have heard the saw
"Give a man a fish and he eats for a day...Teach a man to fish and he
eats for a lifetime." Appears my neglect has made you learn to fish
;-). Trust me. I am not being arrogant. I have been given many
fishes in these groups and while I catch some from time to time I still
often beg for and I am spoon fed fish ;-).
 
G

Guest

Greg,
Quite the contrary. I can imagine that I might have sounded somewhat
arrogant when I told people at work that i finally got the form to work as we
wanted.

Thanks again,
Aldon
 

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