PDA

View Full Version : Solved: Spell Check a Form Field



TButhe
03-15-2005, 02:00 PM
Hi everyone,
I have a form that has several (41 to be exact) text form fields in a table. They want them to be spell checked. I cannot figure out the code to spell check a form field. I have used bookmarks for each text field but when i reference the bookmark it just rifles thru each text field and doesn't bring up the Spelling and Grammar dialog box. The code below is just a small part of my macro. I'm sure there is a quicker and better way to do this but I am just a beginner. :bink: I have repeated the two "Selection" lines for each of the numerous text boxes and have assigned the macro to a toolbar button.

Private Sub ChkSpl()
ActiveDocument.Unprotect
Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
Selection.Range.CheckSpelling
Selection.GoTo What:=wdGoToBookmark, Name:="Text2"
Selection.Range.CheckSpelling
End Sub

I have had success with similar code but I was pulling it from a user form to a bookmark. I am not allowed to alter the appearance of the form that this needs to go into so cannot change the layout, etc. I also cannot attach a copy of the form because it would be considered confidential. :whyme:

I did look at the KB and dug thru all the posts but couldn't find anything. Am I going about this wrong?:aw

Thanks for your assistance!!

Anne Troy
03-15-2005, 02:03 PM
Sorry. I'm in a hurry. Go to google. Type "word mvps" without the quotes. Take the first hit you get. Go to the macros tab at the top of the page, do a search for spell check form fields (or similar). They've got some code that I've never been able to make work.

TButhe
03-15-2005, 02:14 PM
I have tried that and it doesn't work for me either. I will keep trying!! Maybe I can get a few ideas from digging deeper into it. Thanks, Dreamboat!:bow:

Anne Troy
03-15-2005, 02:22 PM
Well, Gerry or Tony should be by soon. They're the Word VBA Geeks. :)

mdmackillop
03-15-2005, 02:33 PM
Hi,
From the microsoft help.

http://support.microsoft.com/default.aspx?scid=kb;en-us;191028

Method 3: Unprotect, Check Spelling or Update a Field, Reprotect a Document

Because form field text is formatted for No Proofing, you can use the following macro to: ?Temporarily unprotect the form.?Change the language of the form fields.?Perform a spelling check or update a field.?Reprotect the form while preserving the text you've typed into the form fields.You can use this macro as an On Exit macro for the last form field so you can check the spelling or update a field before you save the form.


Sub FormsSpellCheck()

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

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

' 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

TButhe
03-15-2005, 02:47 PM
THANKS for your quick response!!!:clap2:
Ok, I wasn't specific enough - its a major flaw of mine :banghead: - I don't want them to have to check the protected info in the rest of the table. Just the form fields. SORRY!!:omg2:

TButhe
03-16-2005, 02:32 PM
I got it (well it's working) but I'm sure it could be cleaned up. I had to add a bookmark to each form field and then assigned this code to a toolbar button.
Private Sub mysplchk()
Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = False
Selection.Range.CheckSpelling
End Sub

I had to add these 4 lines for each form field. I am going to mark this resolved. Thanks again everyone. :hi: