Password-Related Properties

The Document object has several properties related to document passwords:

HasPassword property

This read-only property returns True if a password is required to open the specified document.

Password property

Sets a password (as a string) that must be supplied to open the document. This an example of a relatively rare write-only property. In other words, you can write the password, but not read it!

The WritePassword property

Sets a password for modifying the document (that is, writing to the document, hence the name). It is also a write-only string. Note that a document can still be opened without knowing this password.

Get Writing Word Macros, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.