Solved

Can spell checking be enabled in Word protected form?

Posted on 2013-01-20
18
3,161 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
18 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 400 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now