TomQA17025
asked on
Can spell checking be enabled in Word protected form?
Is there a way for me to password protect a Word 2010 form, but still permit spell checking using the "content controls", not the "legacy tools"?
ASKER
I left out that the form is protected, but permits "filling in forms". I must keep the form password protected to ensure that my users don't change it.
The only simple way to allow spell checking is to remove the forms protection. This, and re-protection, can be done in VBA macro code.
In theory, it would be possible to have a macro to check the spelling of the contents of each form field or content control and to present a message box or a Userform to report that to the current document editor. However it would take same considerable effort and would not look the same as the usual spell check.
In theory, it would be possible to have a macro to check the spelling of the contents of each form field or content control and to present a message box or a Userform to report that to the current document editor. However it would take same considerable effort and would not look the same as the usual spell check.
Hmm, I've done a search. It seems that I wrote some code a couple of years ago, here:
https://www.experts-exchange.com/questions/26352341/How-do-I-enable-spell-checking-for-text-boxes-in-a-MS-Word-2007.html. The code is for form fields, but if you think that such a solution would be acceptable, I can (hopefully) modify it for content controls.
https://www.experts-exchange.com/questions/26352341/How-do-I-enable-spell-checking-for-text-boxes-in-a-MS-Word-2007.html. The code is for form fields, but if you think that such a solution would be acceptable, I can (hopefully) modify it for content controls.
Option Explicit
Sub FormFieldSpelling()
Dim sugs As SpellingSuggestions
Dim sug As SpellingSuggestion
Dim ffld As FormField
Dim wrd As Range
ActiveDocument.Unprotect 'password
For Each ffld In ActiveDocument.FormFields
If ffld.Type = wdFieldFormTextInput Then
For Each wrd In ffld.Range.words
With wrd.Find
.MatchWildcards = True
.Text = "[a-zA-Z]{1,}" 'only test alphabetic
If .Execute Then
Set sugs = GetSpellingSuggestions(wrd.Text)
If sugs.count > 0 Then
wrd.Font.Color = vbRed
Else
wrd.Font.Color = &HFF000000
End If
End If
End With
Next wrd
End If
Next ffld
ActiveDocument.Protect wdAllowOnlyFormFields, True ',password
End Sub
Sub ClearRedFont()
Dim ffld As FormField
ActiveDocument.Unprotect 'password
For Each ffld In ActiveDocument.FormFields
If ffld.Type = wdFieldFormTextInput Then
ffld.Range.Font.Color = &HFF000000
End If
Next ffld
End Sub
ASKER
Graham, I'd appreciate it if you could make it work with content controls and, if possible, the legacy controls, but what would trigger the macro? Also, does the macro invoke the Word spell checker? We have losts of technical words that have been added to the Word spell checker.
Thanks,
Tom
Thanks,
Tom
The macro could be started via a 'Quick Access Toolbar' button and/or a shortcut keystroke. Use the dropdown opened via the arrow to the right of the QAT and chose 'More commands' to open the 'Word Options' dialogue at the Customize page. Select Macros from the 'Choose commands from'
Here are the modified macros
Here are the modified macros
Sub ContentControlSpelling()
Dim sugs As SpellingSuggestions
Dim sug As SpellingSuggestion
Dim cc As ContentControl
Dim wrd As Range
ActiveDocument.Unprotect 'password
For Each cc In ActiveDocument.ContentControls
If cc.Type = wdContentControlRichText Or cc.Type = wdContentControlText Then
For Each wrd In cc.Range.Words
Set sugs = GetSpellingSuggestions(wrd.Text)
If sugs.Count > 0 Then
wrd.Font.Color = vbRed
Else
wrd.Font.Color = &HFF000000
End If
Next wrd
End If
Next cc
ActiveDocument.Protect wdAllowOnlyFormFields, True ',password
End Sub
Sub ClearRedFontCC()
Dim cc As ContentControl
ActiveDocument.Unprotect 'password
For Each cc In ActiveDocument.ContentControls
If cc.Type = wdContentControlRichText Or cc.Type = wdContentControlText Then
cc.Range.Font.Color = &HFF000000
End If
Next cc
ActiveDocument.Protect wdAllowOnlyFormFields, True ',password
End Sub
ASKER
Graham,
This is exciting!! I added the macro to a QAT button, protected the document and saved it.
The macro found my misspelled words by using a red underline, but then gave this error:
Run-time error 4120, bad parameter and pointed to this line:
Set sugs = GetSpellingSuggestions(wrd .Text)
- Tom
This is exciting!! I added the macro to a QAT button, protected the document and saved it.
The macro found my misspelled words by using a red underline, but then gave this error:
Run-time error 4120, bad parameter and pointed to this line:
Set sugs = GetSpellingSuggestions(wrd
- Tom
I can't reproduce that. Perhaps we should look at the value of wrd.text before the line is executed.
Can you put insert a line, and tell us what the last thing in the Immediate window is when it fails?
Can you put insert a line, and tell us what the last thing in the Immediate window is when it fails?
For Each wrd In cc.Range.Words
Debug.Print "wrd.text: (" & wrd.text & ")" '< ---new line
Set sugs = GetSpellingSuggestions(wrd.Text)
ASKER
Graham - 02/07/013 - are you there? I answered your question on 01/21/13. I'm hoping you can solve this one problem with the macro.
From my 01/21/13 reply
I've attached the form without the macros so you can see where the values come from, but the Immediate window has:
wrd.text: (Joe )
wrd.text: (Smith)
wrd.text: (100)
wrd.text: (Footman)
wrd.text: (Compariison )
wrd.text: (of )
wrd.text: (horsas )
wrd.text: (Processing )
wrd.text: (and )
wrd.text: (prnting )
wrd.text: (Footman )
wrd.text: (activities )
wrd.text: (Click )
wrd.text: (here )
wrd.text: (to )
wrd.text: (enter )
wrd.text: (text)
wrd.text: (.)
The form was protected when I ran my tests.
Thoughts?
Smith-TEST-No-Macros.docx
From my 01/21/13 reply
I've attached the form without the macros so you can see where the values come from, but the Immediate window has:
wrd.text: (Joe )
wrd.text: (Smith)
wrd.text: (100)
wrd.text: (Footman)
wrd.text: (Compariison )
wrd.text: (of )
wrd.text: (horsas )
wrd.text: (Processing )
wrd.text: (and )
wrd.text: (prnting )
wrd.text: (Footman )
wrd.text: (activities )
wrd.text: (Click )
wrd.text: (here )
wrd.text: (to )
wrd.text: (enter )
wrd.text: (text)
wrd.text: (.)
The form was protected when I ran my tests.
Thoughts?
Smith-TEST-No-Macros.docx
Sorry. I noticed that there were no Content Controls in the document that you posted, but must have forgotten to get back to you.
ASKER
Hi Graham,
I appreciate you getting back to me! I'm confused regarding your statement that there are no Content Controls in the form I posted. It has plenty of Rich Text Content Controls.
Regards,
Tom
I appreciate you getting back to me! I'm confused regarding your statement that there are no Content Controls in the form I posted. It has plenty of Rich Text Content Controls.
Regards,
Tom
Perhaps I was looking at the wrong document. I'll try again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Graham,
Your macros works great, both the spell check in content controls and removing the red font from mispelled words. I really appreciate your efforts!
Thank you!
Tom
Your macros works great, both the spell check in content controls and removing the red font from mispelled words. I really appreciate your efforts!
Thank you!
Tom
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for TomQA17025's comment #a38908002
for the following reason:
Graham is quick to create a solution and sticks with you until your satisfied. We just had a little delay on this question.
Accepted answer: 0 points for TomQA17025's comment #a38908002
for the following reason:
Graham is quick to create a solution and sticks with you until your satisfied. We just had a little delay on this question.
ASKER
Graham,
I really meant to award the points to you. My mistake.
Graham is quick to create a solution and sticks with you until your satisfied. We just had a little delay on this question.
Thank you
Tom
I really meant to award the points to you. My mistake.
Graham is quick to create a solution and sticks with you until your satisfied. We just had a little delay on this question.
Thank you
Tom
Anyone having the password can make changes and re-protect the new form before saving it
http://www.technipages.com/word-2010-password-protect-document-file.html