Password Property
TOC
Collapse the table of content
Expand the table of content

Document.Password Property (Word)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

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

expression .Password

expression A variable that represents a Document object.

Important note 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.

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

Set myDoc = Documents _ 
 .Open(FileName:="C:\My Documents\Earnings.doc") 
myDoc.Password = strPassword 
myDoc.Close
Show:
© 2016 Microsoft