Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forms Spellcheck (Word 2000)

    The Word MVP site lists a macro for spell checking forms & our own Geoff contributed to it. However, I'm wondering if a modification could be made (Geoff <img src=/S/smile.gif border=0 alt=smile width=15 height=15>). The code is located at <A target="_blank" HREF=http://www.mvps.org/word/FAQs/MacrosVBA/SpellcheckProtectDoc.htm>How to enable the spellchecker in a protected document</A>. When I run the code & click cancel, the spellchecker continues to go to each text form field. In other words, I have to click cancel for each form field. Can the code (reproduced below) be modified to a user to cancel once?

    Thanks in advance.

    Option Explicit

    Sub RunSpellcheck()

    Dim ProtectionType As Long, oDoc As Document, oSection As Section, _
    OriginalRange As Range

    'If no documents open, quit macro
    If Documents.Count = 0 Then
    Exit Sub
    End If

    Set oDoc = ActiveDocument
    Set OriginalRange = Selection.Range

    'Check what type of protection - if any - has been applied
    Select Case oDoc.ProtectionType
    'If protected for tracked changes, or if not protected,
    'run spellchecker and quit
    Case wdNoProtection, wdAllowOnlyRevisions
    oDoc.Range.CheckSpelling
    Exit Sub
    Case wdAllowOnlyComments
    'Don't want to run spellchecker if protected for comments
    Exit Sub
    End Select

    System.Cursor = wdCursorWait

    'If we've got this far, it's protected for forms
    'Now unprotect the document
    oDoc.Unprotect

    'Check each section for its protection property -
    'which you can get even afer unprotecting the document.
    'If the section was protected, call a subroutine to spellcheck the formfields
    'if it wasn't, spellcheck the section

    For Each oSection In oDoc.Sections
    If oSection.ProtectedForForms Then
    Call CheckProtectedSection(oSection)
    Else
    If oSection.Range.SpellingErrors.Count > 0 Then
    oSection.Range.CheckSpelling
    End If
    End If
    Next oSection

    'Re-protect the document
    oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    OriginalRange.Select
    System.Cursor = wdCursorNormal

    End Sub


    --------------------------------------------------------------------------------

    Sub CheckProtectedSection(oSection As Section)

    Dim CorrectedError As String, FmFld As FormField, MyRange As Range

    'check only the text formfields,
    'don't check listboxes and checkboxes - this speeds up the code

    For Each FmFld In oSection.Range.FormFields
    'Check to see if the field is a text formfield
    If FmFld.Type = wdFieldFormTextInput Then
    'Check if the field is a 'real' text field (no date, formula etc)
    If FmFld.TextInput.Type = wdRegularText Then

    'The following subroutine won't be called if Word 97 is in use
    If Not Left$(Application.Version, 1) = "8" Then
    Call TurnNoProofingOff(FmFld)
    End If

    'Change the language constant in the following line if necessary;
    'when you type the = sign, a list of all supported language constants will
    'appear, and you can choose one from the list.
    FmFld.Range.LanguageID = wdEnglishUS 'Or whichever is appropriate for you

    'Spellcheck the text in the current form field
    If FmFld.Range.SpellingErrors.Count > 0 Then

    'Set a range to the formfield's range in case the user
    'accidentally destroys the formfield by overtyping its entire contents
    Set MyRange = FmFld.Range

    FmFld.Select

    Application.ScreenRefresh
    Selection.Range.CheckSpelling

    If Not IsObjectValid(FmFld) Then
    'If formfield was destroyed when the user corrected the spelling,
    'reinstate it, and put the user's correction into its result
    CorrectedError = MyRange.Text
    ActiveDocument.Undo
    FmFld.Result = CorrectedError
    End If

    Application.ScreenRefresh

    End If
    End If
    End If
    Next FmFld

    End Sub


    --------------------------------------------------------------------------------

    Sub TurnNoProofingOff(FmFld As FormField)
    'This subroutine is called only in Word 2000 and above
    FmFld.Range.NoProofing = False
    End Sub

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

    Re: Forms Spellcheck (Word 2000)

    Phil,

    I don't know how to do it!

    The key line is:<pre>Selection.Range.CheckSpelling
    </pre>

    which displays the dialog box for the spelling changes (and another "CheckSpelling" for checking in an unprotected section). I don't know how to interrogate the results of this, to know if "Close" was pressed.

    My contribution was to check in unprotected sections if a form was partially protected.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms Spellcheck (Word 2000)

    Hi Geoff:

    Thanks for looking into this. If it can't be done, it can't be done.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms Spellcheck (Word 2000)

    Normally, if you use the Dialogs(wdDialogConstant) method, you get back different values for different user actions. However, in this case:

    'Selection.Range.CheckSpelling
    With Dialogs(846)
    MsgBox .Show 'same result with .Display
    End With

    The dialog always seems to return -1 (meaning, presumably, dialog completed successfully, irrespective of the user's choices).

    An interesting way to try to tackle this would be to inspect the undo buffer to see if the user made a "Spelling Change". However, I don't see any programmatic access to the descriptions on the Undo list (I can clear it, I can execute it, but I can't see what it is). So... I think Phil is stuck unless he wants to code his own dialog.

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms Spellcheck (Word 2000)

    Hi Jefferson & Geoff:

    I copied this code from the MS kb <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q191/0/28.ASP>Q191028 - WD2000: How to Retain Information Typed into a Form Field When You Protect a Form</A>. I've only briefly tested it but it seems to spell check the document, both protected & unprotected sections, & responds to either the escape key or close button. It does seem to take a while to execute, however. I'm wondering if you know what this code will not do.

    <pre>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</pre>


    Thanks again.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Forms Spellcheck (Word 2000)

    Phil

    It doesn't look like it reprotects only the sections that were protected initially (assuming the entire document wasn't protected to start with)
    Andrew Lockton, Chrysalis Design, Melbourne Australia

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

    Re: Forms Spellcheck- reply from Dave Rado

    Phil,

    I forwarded your message to Dave, and he's asked me to post the following:

    The problems with the macro in the KB are:

    1) It spellchecks (and lets the user amend) the protected parts of the form that *don't* contain form fields (yuk!)

    2) It even spellchecks (and lets the user amend) the headers and footers!

    3) It destroys the formfields, if you overtype the entire contents of a form field. in the top pane of the spellcheck dialog In short its was obviously written by someone who didn't have to deploy it in the real world!!!

    Regarding the issue of the cancel button, I don't know if it's possible but am looking into it.

    The problem with using the Dialogs object, BTW, is that it doesn't work properly. You *can* intercept the event of its being cancelled, like this:

    <pre>With Dialogs(wdDialogToolsSpellingAndGrammar)
    If .Display > 0 Then
    .Execute
    Else
    Cancelled = True
    Exit Sub
    End If
    End With
    </pre>

    But it doesn't work properly because it doesn't "realise" that it's meant to be checking just the selection, whereas Selection.Range.CheckSpelling does (try it and you'll see). So
    (a) you keep being asked if you want to continue, every time you cklick "Change" (infuriating) and
    ([img]/forums/images/smilies/cool.gif[/img] you can accidentally destroy form fields, again.

    All in all, protected documents are the most appallingly designed mess, and although the "feature" has been around for 5 versions of Word, now, MS still haven't come close to getting their act together on this. Someone ought to crack a few heads together over there .... (I only wish I could! <g>).

    Regards

    Dave
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

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

    Re: Forms Spellcheck (Word 2000)

    Andrew,

    I've just run it, and it appears to reprotect OK- unless I've doce something different from you.

    The line<pre>oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    </pre>

    reprotects the document; the sections to be protected were already set up correctly, and don't need to be changed again.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms Spellcheck (Word 2000)

    Hi Geoff:

    Thanks for posting Dave's reply. I see the problem now--I hadn't tested the code enough. It does reprotect, as you mention, but has other defects. I think I'll live with the code that you've come up with. It'll only be a nuisance in a long form with numerous form fields, & only then if the user cancels.

    Thanks for your help.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms Spellcheck- reply from Dave Rado

    For the record, Dialog 846 is named "ToolsSpellingRange" (I don't know whether it has a wdYadaYada constant defined), and it does check only the current range. However, even though it is only checking the range, it still doesn't operate any better than the global checker. Just thought I would point this out in case anyone was going to dig further.

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms Spellcheck- reply from Dave Rado

    Jefferson, et al:

    The constant for that dialog (846) is

    wdDialogToolsSpellingAndGrammar

    if that's important at this point in the discussion.

    The range is checked if a range is defined or a selection is selected; otherwise the document is spell checked. I swear this is true to the best of my knowledge....
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms Spellcheck- reply from Dave Rado

    Jefferson,

    Do you know where I can a comprehensive list of the numeric constants for Word dialogs?

    846 = wdDialogToolsSpellingAndGrammar

    I've got a few more by experimenting, but I'd like a list.

    Thanks.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

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

    Re: Forms Spellcheck- reply from Dave Rado

    Kevin,

    There's a spreadsheet containing all Office 97 constants <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q112/6/71.asp>here</A>.

    Sorry it's Geoff not Jefferson here.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  14. #14
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms Spellcheck- reply from Dave Rado

    Hey man,

    You are right on...


    Thanks Geoff.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  15. #15
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Forms Spellcheck- reply from Dave Rado

    In Office2000 I get something different in my Immediate window:

    <blockquote><hr>debug.Print wdDialogToolsSpellingAndGrammar

Page 1 of 2 12 LastLast

Posting Permissions

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