#1
|
|||
|
|||
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? |
#2
|
||||
|
||||
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 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 |
#3
|
|||
|
|||
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 If I review all the errors entered in the content controls or press ignore all, I get the same error. |
#4
|
|||
|
|||
But if I want to change the content controls so your code will work, what do I insert instead?
|
#5
|
|||
|
|||
Quote:
I fixed up my typo so now it reads Code:
ActiveDocument.Unprotect ActiveDocument.CheckSpelling ActiveDocument.Protect wdAllowOnlyFormFields |
#6
|
|||
|
|||
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?
|
#7
|
||||
|
||||
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 |
#8
|
|||
|
|||
My content controls are not. I don't think they are, is it possible to run spell check anyway?
|
#9
|
||||
|
||||
Quote:
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
__________________
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. |
#10
|
||||
|
||||
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 |
#11
|
||||
|
||||
Threads merged.
dpaton05: Kindly don't start multiple threads on the same topic.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
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 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 Thanks Graham, Dave |
#13
|
|||
|
|||
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?
|
#14
|
||||
|
||||
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 |
#15
|
|||
|
|||
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. |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Spell Check stopped in middle of document | bsuedmeyer | Word | 6 | 03-20-2016 10:06 AM |
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 |
Spell check not working correctly in table of form document | troybuell | Word | 1 | 07-23-2012 12:08 PM |