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