Can't Spellcheck individual form fields in a protected form

R

Roxy

Is it possible to spellcheck only certain form fields in a protected Word
form?
Below is the Macro I have so far but it runs through all the form fields
including the check boxes and I have a 40 page doc which takes almost 5 mins
for the spellchecker to run. I have tried to use the macro in the 'on exit'
properties but that still doesn't seem to work. Any ideas would be greatly
appreciated.
~Thanks, Roxy

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
 
J

Jean-Guy Marcil

Roxy said:
Is it possible to spellcheck only certain form fields in a protected Word
form?
Below is the Macro I have so far but it runs through all the form fields
including the check boxes and I have a 40 page doc which takes almost 5 mins
for the spellchecker to run. I have tried to use the macro in the 'on exit'
properties but that still doesn't seem to work. Any ideas would be greatly
appreciated.

For a complete discussion on the subject, see
http://word.mvps.org/faqs/macrosvba/SpellcheckProtectDoc.htm
 
R

Roxy

Thank you but I have tried that numerous times and it doesn't work for me
either. Any other suggestions?
 
J

Jean-Guy Marcil

Roxy said:
Thank you but I have tried that numerous times and it doesn't work for me
either. Any other suggestions?

The code on that page works. I have used it numerous times.
Just so you know, in case you need to post a question again in the future,
"it doesn't work " is totally unhelpful. We cannot help based on a statement
like this.

The code on the page I suggested covers all eventualities, your code doesn't.
However, you may decide to use your own code, I have no problem with that.

Did you at least look at the code on the page I suggested?
Look for the the sub called:
Private Sub CheckProtectedSection(oSection As Section)
The answer to your original question is in there.
As I wrote in my previous post, that page is complete...everything is there,
you may have to read a bit though...

Good luck.
 
R

Roxy

Yes, when I tried the code from the MVP page I ran into trouble when I needed
to unprotect and then reprotect my document. Can you tell me exactly where
to insert into the code:
oDoc.Unprotect Password:="Password"

And:

oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:="Password"

This part I couldn't figure out and I was having a hard time.
Once I get this part to work, do I just leave the code in the doc itself or
do I need to put it as a 'run on exit' function in order to spellcheck one
form field at a time? Thanks so much again for all your help, I have been
just learning by trial and error so if I misspeak or don't make any sence
please forgive me.
~Roxy
 
J

Jean-Guy Marcil

Roxy said:
Yes, when I tried the code from the MVP page I ran into trouble when I needed
to unprotect and then reprotect my document. Can you tell me exactly where
to insert into the code:
oDoc.Unprotect Password:="Password"

And:

oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:="Password"

This part I couldn't figure out and I was having a hard time.
Once I get this part to work, do I just leave the code in the doc itself or
do I need to put it as a 'run on exit' function in order to spellcheck one
form field at a time? Thanks so much again for all your help, I have been
just learning by trial and error so if I misspeak or don't make any sence
please forgive me.

On the page
http://word.mvps.org/faqs/macrosvba/SpellcheckProtectDoc.htm
point number 2 is where you got the code you posted above.

The web page assumes that you will be using the code it provides, threfore
you are supposd to replace the lines in the code in point one by the ones in
point 2. Now, I believe that you are using your own code...

You posted the following code in your original message:


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"


You are already unprotecting/re-protecting with a password... I do not
understand why you are trying to do it again.

As to your second question "Once I get this part to work, do I just leave
the code in the doc itself or (...)", the answer is on the same web page, see
point #3.
Users have to initate the spell checking with a menu/toolbar button or a
keyboard shortcut, which is the standard with all documents... Point #3 has a
link that takes you to a page that tells how to do this. That second page
also has a link that takes you to another page that tells you how to link a
macro to a hotkey...
 
R

Roxy

Thank you for your quick responses.
When I copy and paste the exacty as it is from the website it get an error
message "Password Incorrect", because I have my forms protected with a
password that only I the creator will know and none of the users will know.
I thought you need to program into the code with the password to unprotect,
run spellcheck, reprotect so the user doesn't get asked what the password is.
Am I incorrect?
 
J

Jean-Guy Marcil

Roxy said:
Thank you for your quick responses.
When I copy and paste the exacty as it is from the website it get an error
message "Password Incorrect", because I have my forms protected with a

Don't tell me you pasted the code exactly as is without editing it to use
*your* password... Have you changed "Password" to "colleen"?
password that only I the creator will know and none of the users will know.
I thought you need to program into the code with the password to unprotect,
run spellcheck, reprotect so the user doesn't get asked what the password is.
Am I incorrect?

Not quite. If you use the correct password in the code, all you need is
protect the document manually using that password; then the code will work.
Of course, if you use password A when locking up the form and then using
password B in the code, it won't work... Or, if you use Password A to
unprotect, and then Password B to protect, the next time the code runs, it
won't work either...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top