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"?
TomQA17025Asked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
Yes. I downloaded your document again and found that I had crossed over two folders when saving and hence was looking at the wrong document. (I'll have to check what I did with the other question.)

The GetSpellingSuggestions method baulks at the full stop.
Here is some revised code to check that there are only letters in the word being tested.
 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
                If IsAlphabetic(wrd.Text) Then
                    Set sugs = GetSpellingSuggestions(wrd.Text)
                    If sugs.count > 0 Then
                        wrd.Font.Color = vbRed
                    Else
                        wrd.Font.Color = &HFF000000
                    End If
                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
Function IsAlphabetic(strText As String) As Boolean
    If Len(strText) > 0 Then
        IsAlphabetic = (Abs(Asc(UCase(strText)) - Asc("N") + 0.5) < 13.5)
    End If
End Function

Open in new window

0
 
Michael-BestCommented:
Password protected forms prevent people from viewing or modifying documents unless they have a password
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
0
 
TomQA17025Author Commented:
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.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
GrahamSkanRetiredCommented:
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.
0
 
GrahamSkanRetiredCommented:
Hmm, I've done a search. It seems that I wrote some code a couple of years ago, here:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_26352341.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

Open in new window

0
 
TomQA17025Author Commented:
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
0
 
GrahamSkanRetiredCommented:
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
 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

Open in new window

0
 
TomQA17025Author Commented:
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
0
 
GrahamSkanRetiredCommented:
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?
            For Each wrd In cc.Range.Words
                Debug.Print "wrd.text: (" & wrd.text & ")"  '< ---new line
                Set sugs = GetSpellingSuggestions(wrd.Text)

Open in new window

0
 
TomQA17025Author Commented:
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
0
 
GrahamSkanRetiredCommented:
Sorry. I noticed that there were no Content Controls in the document that you posted, but must have forgotten to get back to you.
0
 
TomQA17025Author Commented:
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
0
 
GrahamSkanRetiredCommented:
Perhaps I was looking at the wrong document. I'll try again.
0
 
TomQA17025Author Commented:
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
0
 
TomQA17025Author Commented:
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.
0
 
TomQA17025Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.