Share via


Document.Protect Method

Applies one of several types of protection to the document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Sub Protect ( _
    Type As WdProtectionType, _
    ByRef NoReset As Object, _
    ByRef Password As Object, _
    ByRef UseIRM As Object, _
    ByRef EnforceStyleLock As Object _
)
void Protect(
    WdProtectionType Type,
    ref Object NoReset,
    ref Object Password,
    ref Object UseIRM,
    ref Object EnforceStyleLock
)

Parameters

  • NoReset
    Type: System.Object%
    false to reset form fields to their default values. true to retain the current form field values if the document is protected. If Type is not wdAllowOnlyFormFields, the NoReset argument is ignored.
  • Password
    Type: System.Object%
    The password required to remove protection from the document. (See Remarks below.)
  • UseIRM
    Type: System.Object%
    Specifies whether to use Information Rights Management (IRM) when protecting the document from changes.
  • EnforceStyleLock
    Type: System.Object%
    Specifies whether formatting restrictions are enforced in a protected document.

Remarks

When a document is protected, users can make only limited changes, such as adding annotations, making revisions, or completing a form. If the document is already protected when you use this method, an exception is thrown.

Avoid using hard-coded passwords in your applications. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

.NET Framework Security

See Also

Reference

Document Interface

Microsoft.Office.Tools.Word Namespace