Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-01-2019, 11:35 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default How can you run spell check on a protected document

I have a document that needs to be protected so users can't edit it but I need to be able to run a spell check on the controls that the user can type into. Can anyone help me with this please?
Reply With Quote
  #2  
Old 07-02-2019, 01:59 AM
gmayor's Avatar
gmayor gmayor is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You need a macro stored in the document to unprotect the document, run the spell check then re-protect it again e.g.

Code:
Sub SpellCheckForm()
Dim i As Integer
Dim bProtected As Boolean
    'Unprotect the file
    If Not ActiveDocument.ProtectionType = wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If
    ActiveDocument.Range.NoProofing = True
    'check each formfield for spelling
    For i = 1 To ActiveDocument.FormFields.Count
        ActiveDocument.FormFields(i).Select
#If VBA6 Then
        Selection.NoProofing = False
#End If
        Selection.LanguageID = wdEnglishUK
        Selection.Range.CheckSpelling
    Next
    'Reprotect the document.
    If bProtected = True Then
        ActiveDocument.Protect _
                Type:=wdAllowOnlyFormFields, _
                NoReset:=True, _
                Password:=""
    End If
lbl_Exit:
    Exit Sub
End Sub
Alternatively you could create the document using content controls which don't require a macro to check the contents.

If you want to restrict editing to the controls then you would add 'Editors' to the controls and protect the form as read only which limits editing to the controls. The spell check will still work with the document protected.

You may find Insert Content Control Add-In useful for both inserting the controls and applying the editors.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 07-02-2019, 04:38 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default

Thanks for your reply. I already have a document with content controls on it and I wasn't sure of your instructions for using content controls. I am using a computer at work so I don't have permissions to install additional software.


I have the following code in a command button on the document.
Code:
ActiveDocument.Unprotect
ActiveDocument.CheckSpelling
ActiveDocument.Unprotect
The issue is that you can press the button and the spell check starts and starts checking spelling of the content controls and if I press cancel on the spell checker, I get the error "The unprotect method or property is not available because the document is already unprotected".



If I review all the errors entered in the content controls or press ignore all, I get the same error.
Reply With Quote
  #4  
Old 07-02-2019, 05:01 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default

But if I want to change the content controls so your code will work, what do I insert instead?
Reply With Quote
  #5  
Old 07-02-2019, 05:54 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default

Quote:
Originally Posted by dpaton05 View Post
Code:
ActiveDocument.Unprotect
ActiveDocument.CheckSpelling
 ActiveDocument.Unprotect

I fixed up my typo so now it reads

Code:
ActiveDocument.Unprotect
ActiveDocument.CheckSpelling
ActiveDocument.Protect wdAllowOnlyFormFields
Now when I try and run it, a window is displayed saying "we're finished checking your selection. Want to check the rest of the document" and I press yes and then nothing happens, even though I have deliberately entered spelling errors. These errors have been in both the content controls and as regular text.
Reply With Quote
  #6  
Old 07-02-2019, 07:00 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default Loop through all content controls on a form

I need some vba code that will loop through all content controls on a form to run spell check on each control. Can someone help me with this please?
Reply With Quote
  #7  
Old 07-02-2019, 08:10 PM
gmayor's Avatar
gmayor gmayor is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Content controls are spell checked automatically as you type, if the appropriate option is set in File > Options > Proofing and the style used to format the control does not have the no proofing option set. (Press F7 to run a complete spell check).
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #8  
Old 07-02-2019, 08:19 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default

My content controls are not. I don't think they are, is it possible to run spell check anyway?
Reply With Quote
  #9  
Old 07-02-2019, 08:24 PM
gmayor's Avatar
gmayor gmayor is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
Originally Posted by dpaton05 View Post
But if I want to change the content controls so your code will work, what do I insert instead?
Run the following macro
Code:
Sub addEditors()
Dim oCC As ContentControl
    If Not ActiveDocument.ProtectionType = wdNoProtection Then
        ActiveDocument.Unprotect
    End If
    For Each oCC In ActiveDocument.ContentControls
        oCC.Range.Editors.add (wdEditorEveryone)
    Next oCC
    ActiveDocument.Protect Type:=wdAllowOnlyReading, NoReset:=True
lbl_Exit:
    Set oCC = Nothing
    Exit Sub
End Sub
which will add the editors to the content controls and then the macro to check the spelling is not required as the spell check will be automatic. Note the content controls are not protected for forms, but are marked as regions that may be edited.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Last edited by gmayor; 07-02-2019 at 11:02 PM.
Reply With Quote
  #10  
Old 07-02-2019, 11:04 PM
gmayor's Avatar
gmayor gmayor is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

They are not checked automatically if you have protected the document for forms. See your other thread which explains how to protect them and have them work.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #11  
Old 07-03-2019, 02:25 AM
macropod's Avatar
macropod macropod is offline How can you run spell check on a protected document Windows 7 64bit How can you run spell check on a protected document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Threads merged.

dpaton05: Kindly don't start multiple threads on the same topic.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 07-04-2019, 05:23 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default

Sorry about that Paul.



Graham, I still can't get it working. I am still learning vba and don't fully understand this yet. I have a command button with your addEditors code in it and when I click it, nothing happens. I then type in errors and nothing happens, even if I click it again.


I have 3 buttons on my document so I could do some testing for the different bits of code trying to get this to work.


This bit of code will protect the document if it is not protected and then appears to do nothing. If it is already protected, nothing appears to happen. You can even type in deliberate errors to the content controls and nothing will happen.

Code:
Sub CommandButton1_Click()

Dim oCC As ContentControl
    If Not ActiveDocument.ProtectionType = wdNoProtection Then
        ActiveDocument.Unprotect
    End If
    For Each oCC In ActiveDocument.ContentControls
        oCC.Range.Editors.Add (wdEditorEveryone)
    Next oCC
    ActiveDocument.Protect Type:=wdAllowOnlyReading, NoReset:=True
lbl_Exit:
    Set oCC = Nothing
    Exit Sub

'    ActiveDocument.Unprotect Password:=""
 '   ActiveDocument.CheckSpelling
  '  ActiveDocument.Protect
    
End Sub
This bit of code does nothing if it is unprotected and if it is protected, it thinks for half a second and then does nothing.
Code:
Private Sub CommandButton2_Click()
Dim i As Integer
Dim bProtected As Boolean
    'Unprotect the file
    If Not ActiveDocument.ProtectionType = wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If
    ActiveDocument.Range.NoProofing = True
    'check each formfield for spelling
    For i = 1 To ActiveDocument.FormFields.Count
        ActiveDocument.FormFields(i).Select
#If VBA6 Then
        Selection.NoProofing = False
#End If
        Selection.LanguageID = wdEnglishUK
        Selection.Range.CheckSpelling
    Next
    'Reprotect the document.
    If bProtected = True Then
        ActiveDocument.Protect _
                Type:=wdAllowOnlyFormFields, _
                NoReset:=True, _
                Password:=""
    End If
lbl_Exit:
    Exit Sub

End Sub

This bit of code has an error with ActiveDocument.Protect
Code:
Private Sub CommandButton3_Click()

Dim i As Integer
Dim bProtected As Boolean
    'Unprotect the file
    If Not ActiveDocument.ProtectionType = wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If
 '   ActiveDocument.Unprotect Password:=""
    ActiveDocument.CheckSpelling
    ActiveDocument.Protect

End Sub
But if I comment that line out, a window appears asking if you want to check from the start of the document. I press yes and then nothing happens, even with errors written in the content controls. This happens with the document protected or not.


Thanks Graham,
Dave
Reply With Quote
  #13  
Old 07-04-2019, 05:48 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default

I have just realised, spell check is not working on my document. Typing in the document and not in the control boxes. What have I done?
Reply With Quote
  #14  
Old 07-04-2019, 07:51 PM
gmayor's Avatar
gmayor gmayor is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Does your document have content controls or legacy form fields? Your CommandButton2 and CommandButton3 code suggest Form Fields as you are applying protection for forms.

Content controls that check spelling should not be protected for forms.

The code to add editors works only with content controls. It should be run once to mark the content controls as areas that may be edited and then protects the rest as read only. The document does not then need macros.

If the content controls are formatted to allow spell checking (before protecting and adding the editors) then the controls don't need a macro to spell check them.

If spell checking is not working in your document check your Word proofing options and the proofing settings of the paragraph styles.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #15  
Old 07-04-2019, 08:32 PM
dpaton05 dpaton05 is offline How can you run spell check on a protected document Windows 10 How can you run spell check on a protected document Office 2016
Novice
How can you run spell check on a protected document
 
Join Date: Jul 2019
Posts: 19
dpaton05 is on a distinguished road
Default

If I hover over the button I used to put the content controls on it says Plain text content control. How do I tell if each control is a legacy form field or a content control?


It is really strange as some of my form fields work, as in their spelling is checked and some won't. I have noticed that the fields that allow their spelling to be checked show a little red squiggly line under the error. The ones that don't allow checking, won't show any line under errors.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can you run spell check on a protected document Spell Check stopped in middle of document bsuedmeyer Word 6 03-20-2016 10:06 AM
How can you run spell check on a protected document Spell Check is marking ALL words copied from downloaded document as mispelled silveringofrose Word 8 03-13-2016 09:23 AM
Protected Document (Form) that allows Spell Check beve56 Word 3 03-21-2014 06:15 PM
Spell check checking only part of document Adeyo Word 1 02-24-2013 10:49 PM
How can you run spell check on a protected document Spell check not working correctly in table of form document troybuell Word 1 07-23-2012 12:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft