Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Document.Password Property

Office 2007
Sets a password that must be supplied to open the specified document. Write-only String.

Syntax

expression.Password

expression   A variable that represents a Document object.

Remarks

 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 Microsoft Office Solution Developers.

Example

This example opens Earnings.doc, sets a password for it, and then closes the document.

Visual Basic for Applications
Set myDoc = Documents _
    .Open(FileName:="C:\My Documents\Earnings.doc")
myDoc.Password = strPassword
myDoc.Close



Community Additions

ADD
Show:
© 2015 Microsoft