Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Spellcheck in Word with Form fields

    Here is a macro I made for Word 97 to spellcheck my form boxes in a document. We use W95 and it seems to lockup some people's workstations but not all. Can anyone tell me why? Thanks

    Sub FormsSpellCheck()

    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:=""
    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

    [img]/w3timages/icons/spook.gif[/img]

  2. #2
    MichaelCollins
    Guest

    Re: Spellcheck in Word with Form fields

    At what point do users lock up? Before or after the spellcheck?

    I don't use Form Fields a lot, but I ran a couple tests on a dummy document and couldn't get it to fail for me (I, too, am using Word97 on a Win95 platform).

    I did worry about the fact that your code, as posted, simultaneously strips the document of it's Protection password and sets the protection to wdAllowOnlyFormFields no matter what it was to begin with, but I'm not sure that is related to the lockup problem. In any event, this is how I addressed those issues:

    Sub FormsSpellCheck()
    'Here is a macro I made for Word 97 to spellcheck my form boxes in a document. _
    We use W95 and it seems to lockup some people's workstations but not all. _
    Can anyone tell me why? Thanks
    Dim lngOriginalProtectionType As Long ' Store original ProtectionType value
    Dim strProtectionPwd As String ' Capture new protection password, if desired

    lngOriginalProtectionType = ActiveDocument.ProtectionType
    '''If ActiveDocument.ProtectionType <> wdNoProtection Then
    ''' ActiveDocument.Unprotect Password:=""
    '''End If ' ActiveDocument.ProtectionType <> wdNoProtection
    If lngOriginalProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:=""
    End If ' lngOriginalProtectionType <> wdNoProtection

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

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

    ' ReProtect the document.
    '''' This (original) code doesn't need the if...then because ProtectionType explicitly was set to wdNoProtection, above; _
    Also, whatever the ProtectionType was before, now it's restricted to wdAllowOnlyFormFields, with no password:
    '''If ActiveDocument.ProtectionType = wdNoProtection Then
    ''' ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    '''End If ' ActiveDocument.ProtectionType = wdNoProtection

    ' NOTE: If there were a password in place before, it's gone, now! So, _
    prompt the user to add one, if desired:
    strProtectionPwd = InputBox(prompt:="Type password if necessary:", Title:="Form Password", Default:="")
    ' Now, restore the original protection, applying the new password (which may = ""):
    ActiveDocument.Protect Type:=lngOriginalProtectionType, NoReset:=True, Password:=strProtectionPwd

    End Sub

    Sorry if the word wrap messes up the code/comments. I'll be happy to take another look if you have some more specifics about when the problem occurs.

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Spellcheck in Word with Form fields

    Hi,

    This doesn't directly answer your question, but it may be a better way of doing things anyway.

    There's a very good macro for spell checking with form fields- one form field at a time, rather than the whole document, at www.mvps.org

    The limitation with that method (as written) is that it does not spell check unprotected sections in a protected document. That could be programmed around- when I have a chance, I intend to do that. At least it does not spell check in the protected part of the document, which is probably not desirable.

    I was confused by a minor point in the post- "W95" was actually Windows 95, I thought it was "Word", and missed a part of your point.

    I'd highly recommend the MVPS site as an excellent resource.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Posting Permissions

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