Consulting

Results 1 to 7 of 7

Thread: Solved: Spell Check a Form Field

  1. #1
    VBAX Regular TButhe's Avatar
    Joined
    Sep 2004
    Location
    Sioux Falls, SD
    Posts
    64
    Location

    Solved: Spell Check a Form Field

    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. I have repeated the two "Selection" lines for each of the numerous text boxes and have assigned the macro to a toolbar button.

    [VBA]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
    [/VBA]
    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.

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

    Thanks for your assistance!!
    Thanks,
    Tracy

  2. #2
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    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.
    ~Anne Troy

  3. #3
    VBAX Regular TButhe's Avatar
    Joined
    Sep 2004
    Location
    Sioux Falls, SD
    Posts
    64
    Location
    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!
    Thanks,
    Tracy

  4. #4
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Well, Gerry or Tony should be by soon. They're the Word VBA Geeks.
    ~Anne Troy

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi,
    From the microsoft help.

    http://support.microsoft.com/default...b;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.

    [VBA]
    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

    [/VBA]

  6. #6
    VBAX Regular TButhe's Avatar
    Joined
    Sep 2004
    Location
    Sioux Falls, SD
    Posts
    64
    Location
    THANKS for your quick response!!!
    Ok, I wasn't specific enough - its a major flaw of mine - I don't want them to have to check the protected info in the rest of the table. Just the form fields. SORRY!!
    Thanks,
    Tracy

  7. #7
    VBAX Regular TButhe's Avatar
    Joined
    Sep 2004
    Location
    Sioux Falls, SD
    Posts
    64
    Location
    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.
    [VBA] Private Sub mysplchk()
    Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
    Selection.LanguageID = wdEnglishUS
    Selection.NoProofing = False
    Selection.Range.CheckSpelling
    End Sub[/VBA]

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •