Protection-Related Properties and Methods
The Document object has the following several properties related to document protection:
- The Protect method and ProtectionType property
The Protect method protects the document from changes. When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.
The syntax of the Protect method is:
DocumentObject.Protect(Type, NoReset, Password)where the required
Typeparameter specifies the protection type for the document. It can be one of the constants in the following enum:Enum WdProtectionType wdNoProtection = -1 wdAllowOnlyRevisions = 0 wdAllowOnlyComments = 1 wdAllowOnlyFormFields = 2 End Enum
NoResetis related to any form fields on the document. For more on this, refer to the help documentation. Finally, the optionalPasswordparameter can be set to a string password that subsequently will be required in order to unprotect the document.Note that if a document is already protected, the Protect method will cause a runtime error, so the document should first be checked by looking at its ProtectionType property, which can assume any of the
WdProtectionTypeconstants described earlier. This is illustrated in the following code:If ActiveDocument.ProtectionType = wdNoProtection Then ActiveDocument.Protect wdAllowOnlyComments,,"midnight" End If
- The UnProtect method
This method removes protection from the document. However, if the document is not currently protected, this method ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access