?
Solved

Can spell checking be enabled in Word protected form?

Posted on 2013-01-20
18
Medium Priority
?
4,112 Views
Last Modified: 2013-02-21
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"?
0
Comment
Question by:TomQA17025
  • 8
  • 7
16 Comments
 
LVL 34

Expert Comment

by:Michael-Best
ID: 38799011
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
 

Author Comment

by:TomQA17025
ID: 38799036
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38799124
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38799162
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
 

Author Comment

by:TomQA17025
ID: 38799215
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38800283
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
 

Author Comment

by:TomQA17025
ID: 38801390
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38802979
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
 

Author Comment

by:TomQA17025
ID: 38803851
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38905996
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
 

Author Comment

by:TomQA17025
ID: 38906106
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38906451
Perhaps I was looking at the wrong document. I'll try again.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1600 total points
ID: 38906560
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
 

Author Comment

by:TomQA17025
ID: 38908002
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
 

Author Comment

by:TomQA17025
ID: 38912720
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
 

Author Closing Comment

by:TomQA17025
ID: 38913714
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question