I want to disable this Restrict Style Changes in protected Microsoft Word documents with VBA Code.
https://helpdeskgeek.com/office-tips/restrict-editing-on-word-documents/
This code doesn't work for me:
Sub DisableCheckBox()
ActiveDocument.Unprotect
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True, enforcestylelock:=False
End Sub
Any ideas?
Thanks very much.
Edit:
OK. I try to explain my problem.
I have many documents. They have Text and Formular Fields to fill with variable short text. The documents are protected to fill only formulars fields and additionally - and this is the problem - there is activate “limit formating to a selection of styles.”
Complete Text with formular fields is formated to Arial 10 pt. Some formular fields are Arial 12 pt.
When user fill text in the protect document the text is Verdana 12 pt, because this is the default style.That’s the reason I want to deactivate the option “limit formating to a selection of styles.”
Next step, I try in my vba code in a new word document:
https://docs.microsoft.com/en-us/office/vba/api/word.document.protect
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True, enforcestylelock:=False Result: “limit formating to a selection of styles” not activated
Then I try in another new document:
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True, enforcestylelock:=True Result: “limit formating to a selection of styles” activated
The code works for new documents (checkbox “limit formating to a selection of styles” is on or off).
Now I try the code for my existing protected documents with activated option “limit formating to a selection of styles.”
ActiveDocument.Unprotect
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True, enforcestylelock:=False
Result: “limit formating to a selection of styles” is NOT deactivated
I don’t know why?
It is only necessary for me to disable the checkbox option “limit formating to a selection of styles.” with VBA (you can see the checkbox in the picture).
Thank you.