Muokkaa

Jaa


Document.Unprotect method (Word)

Removes protection from the specified document. .

Syntax

expression.Unprotect (Password)

expression Required. A variable that represents a Document object.

Parameters

Name Required/Optional Data type Description
Password Optional Variant The password string used to protect the document. Passwords are case-sensitive. If the document is protected with a password and the correct password isn't supplied, a dialog box prompts the user for the password.

Security

Important

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. For recommended best practices on how to do this, see Security notes for Office solution developers.

Remarks

If the document isn't protected, this method generates an error.

Example

This example removes protection from the active document, using the value of the strPassword variable as the password.

If ActiveDocument.ProtectionType <> wdNoProtection Then 
 ActiveDocument.Unprotect Password:=strPassword 
End If

This example removes protection from the active document. Text is inserted, and the document is protected for revisions.

Set aDoc = ActiveDocument 
If aDoc.ProtectionType <> wdNoProtection Then 
 aDoc.Unprotect 
 Selection.InsertBefore "department six" 
 aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword 
End If

See also

Document Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.