_Document.Protect Method 

Helps to protect the specified document from changes. When a document is protected, users can make only limited changes, such as adding annotations, making revisions, or completing a form.

Namespace: Microsoft.Office.Interop.Word
Assembly: Microsoft.Office.Interop.Word (in microsoft.office.interop.word.dll)

Usage

Dim Type As WdProtectionType
Dim NoReset As Object
Dim Password As Object
Dim UseIRM As Object
Dim EnforceStyleLock As Object
Dim _Document1 As _Document
_Document1.Protect(Type, NoReset, Password, UseIRM, EnforceStyleLock)

Syntax

Sub Protect( _
    <InAttribute()> ByVal Type As WdProtectionType, _
    <InAttribute()> Optional ByRef NoReset As Object, _
    <InAttribute()> Optional ByRef Password As Object, _
    <InAttribute()> Optional ByRef UseIRM As Object, _
    <InAttribute()> Optional ByRef EnforceStyleLock As Object _
)
void Protect(
    [In] WdProtectionType Type, 
    [In, Optional] ref object NoReset, 
    [In, Optional] ref object Password, 
    [In, Optional] ref object UseIRM, 
    [In, Optional] ref object EnforceStyleLock
);
public: Void Protect(
    WdProtectionType^ Type, 
    &Object^ NoReset, 
    &Object^ Password, 
    &Object^ UseIRM, 
    &Object^ EnforceStyleLock
);
public void Protect(
    /*in*/WdProtectionType Type, 
    /*in*/System.Object NoReset, 
    /*in*/System.Object Password, 
    /*in*/System.Object UseIRM, 
    /*in*/System.Object EnforceStyleLock
);
function Protect(
     Type : WdProtectionType, 
     NoReset : Object, 
     Password : Object, 
     UseIRM : Object, 
     EnforceStyleLock : Object
);

Parameters

  • Type
    Required. The protection type for the specified document. WdProtectionType.
  • NoReset
    Optional Object. False to reset form fields to their default values. True to retain the current form field values if the specified document is protected. If Type isn't wdAllowOnlyFormFields, the NoReset argument is ignored.
  • Password
    Optional Object. The password required to remove protection from the specified document. (See Remarks below.)
  • UseIRM
    Optional Object. Specifies whether to use Information Rights Management (IRM) when protecting the document from changes.
  • EnforceStyleLock
    Optional Object. Specifies whether formatting restrictions are enforced in a protected document.

Remarks

If the document is already protected when you use this method, an error occurs.

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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000

Target Platforms

See Also

Reference

_Document Interface
Microsoft.Office.Interop.Word Namespace

Other Resources

_Document Members