Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET Word
We would like to enforce and remove different types of Document Protection (Restrict Editing) on a whole Word 2010 document in code.
Our code has worked in previous version of Word but is no longer working with the new version. When changing protection type from
wdAllowOnlyRevisions to wdAllowOnlyFormFields, our code is designed to unprotect the document and then protect it with a new
protection type as follows.
 
ProtectioType = ActiveDocument.ProtectionType
If ProtectioType = wdAllowOnlyRevisions Then
ActiveDocument.Unprotect()
ActiveDocument.Protect(Password:="xxxxx", NoReset:=True, Type:= wdAllowOnlyFormFields, UseIRM:=False, EnforceStyleLock:=False)
End If
 
After ActiveDocument.Unprotect executed, ActiveDocument.ProtectionType becomes -1 which is correct. But in the document
the Restrict Editing pane (From the document ribbon menu Review -> Restrict Editing) settings are not changed. The
"2. Allow only this type of editing in the document:" checkbox is still checked for "Tacked changes". Therefore,
when code ActiveDocument.Protect is executed, wdAllowOnlyFormFields protection type is not applied and it keeps wdAllowOnlyRevisions.
 
However, after unprotecting the document in code and before calling the protect method in code,
the "2. Allow only this type of editing in the document:" checkbox is still checked (in the Review->Restrict
Editing panel in the ribbon menu of the document). As the result, the document is not protected as we want it to be when using the code.
 
Are there any VBA/Word functions we can use to programmatically clear that checkbox in the Restrict Editing panel? Many thanks!
Posted 22-Feb-12 16:15pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I don't have MS Word 2010, but i found interesting article. Read this[^] article, a specially, the section: "Applies to".
  Permalink  
Comments
zengfuxu at 23-Feb-12 20:56pm
   
I know how to protect a word document using VB code ActiveDocument.Protect as described in that article. The problem with Word 2010 document is, after protection type of a document changed programmatically, it fails to save so the document still keeps the original protection type when it is closed and reopened. This is a MS confirmed bug in Word 2010.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 23 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100