Document.WritePassword Property (Word)

Office 2013 and later

Contribute to this content

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

Sets a password for saving changes to the specified document. Write-only String.

expression .WritePassword

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.

If the active document isn't already protected against saving changes, this example sets "secret" as the write password for the document.

Set myDoc = ActiveDocument 
If myDoc.WriteReserved = False Then myDoc.WritePassword = "secret"