Jay
Thu Apr 10 19:01:27 PDT 2008
The code you have checks every field in the body of the document because of the
lines
>For i = 1 To ActiveDocument.FormFields.Count
>ActiveDocument.FormFields(i).Select
To spell-check only the field that's being exited, remove the For statement and
its matching Next statement, and change the second line above to this:
Selection.Bookmarks(1).Select
At the time the exit macro fires, the Selection is still in the formfield. The
Bookmarks(1) expression refers to the bookmark that is part of the formfield, so
selecting it also selects the contents of the formfield. That's all that will be
checked.
I can't guarantee that you won't run into trouble with this macro, because it
doesn't do anything to verify that its assumptions are met or to catch errors. A
lot of the macro on the MVP site consists of that kind of defensive code.
On Thu, 10 Apr 2008 09:00:00 -0700, Roxy <Roxy@discussions.microsoft.com> wrote:
>I had been using the following code to try to just check individual form
>fields, but ran into trouble cause I could figure out how to change the code
>to do a range so it runs "on exit" and stops in just that form field instead
>of what it is currently now doing and checking the field and then continuing
>on and checking the rest of the fields in the document:
>
>Sub SpellCheckForm()
>Dim i As Integer
>Dim bProtected As Boolean
>
>'Unprotect the file
>If ActiveDocument.ProtectionType <> wdNoProtection Then
>bProtected = True
>ActiveDocument.Unprotect Password:="colleen"
>
>End If
>
>'check formfield for spelling
>For i = 1 To ActiveDocument.FormFields.Count
>ActiveDocument.FormFields(i).Select
>#If VBA6 Then
>Selection.NoProofing = False
>#End If
>Selection.LanguageID = wdEnglishUS
>Selection.Range.CheckSpelling
>Next
>
>'Reprotect the document.
>If bProtected = True Then
>ActiveDocument.Protect _
>Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="colleen"
>End If
>End Sub
>
>"Jay Freedman" wrote:
>
>> The macro from the article is built around the idea of checking all the fields
>> in the document in one pass. It would be quite difficult to make little changes
>> here and there to make it check only one field; it would actually be much easier
>> to write a completely separate macro to do that. Unfortunately I don't have the
>> time to do that now.
>>
>> On Wed, 9 Apr 2008 09:46:02 -0700, Roxy <Roxy@discussions.microsoft.com> wrote:
>>
>> >That work perfectly, thank you!
>> >Now I have the macro set to run "on exit" on certain form fields, as I have
>> >a 40 page document and don't want the spell checker to run thru the whole
>> >thing, just bits at a time. But when I have it set on run "on exit" it
>> >doesn't stop after just that particular form field it keeps on going. Is
>> >there any way to have the code make it stop so you can continue to tab to the
>> >next form field with out the spell checker running thru the entire document?
>> >Thanks again for all your patience and continued help!
>> >
>> >~Roxy
>> >
>> >"Jay Freedman" wrote:
>> >
>> >> On Mon, 7 Apr 2008 16:47:01 -0700, Roxy <Roxy@discussions.microsoft.com> wrote:
>> >>
>> >> >I am trying to use the code from
>> >> >
http://word.mvps.org/faqs/macrosvba/SpellcheckProtectDoc.htm
>> >> >and I got an error that the password was incorrect so I tried to follow the
>> >> >directions from the website but I am still unsure where to insert
>> >> >oDoc.Unprotect Password:="colleen"
>> >> >And:
>> >> >oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
>> >> > Password:="colleen"
>> >> >in to the code in the right places to get it to work. Help anybody? Thanks!
>> >> >~Roxy
>> >>
>> >> In the code, find these lines:
>> >>
>> >> 'If we've got this far, it's protected for forms
>> >> 'Now unprotect the document
>> >> oDoc.Unprotect
>> >>
>> >> and replace the oDoc.Unprotect line with
>> >>
>> >> oDoc.Unprotect Password:="colleen"
>> >>
>> >>
>> >> Then find the lines
>> >>
>> >> 'Re-protect the document
>> >> oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
>> >>
>> >> and replace the second of those lines with
>> >>
>> >> oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
>> >> Password:="colleen"
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.