This documentation is archived and is not being maintained.

Workbook.SetPasswordEncryptionOptions Method

Office 2007
Sets the options for encrypting workbooks using passwords.


expression.SetPasswordEncryptionOptions(PasswordEncryptionProvider, PasswordEncryptionAlgorithm, PasswordEncryptionKeyLength, PasswordEncryptionFileProperties)

expression   A variable that represents a Workbook object.


NameRequired/OptionalData TypeDescription
PasswordEncryptionProviderOptionalVariantA case sensitive string of the encryption provider.
PasswordEncryptionAlgorithmOptionalVariantA case sensitive string of the algorithmic short name (i.e. "RC4").
PasswordEncryptionKeyLengthOptionalVariantThe encryption key length which is a multiple of 8 (40 or greater).
PasswordEncryptionFilePropertiesOptionalVariantTrue (default) to encrypt file properties.


The PasswordEncryptionProvider, PasswordEncryptionAlgorithm, and PasswordEncryptionKeyLength arguments are not independent of each other. A selected encryption provider limits the set of algorithms and key length that can be chosen.

For the PasswordEncryptionKeyLength argument there is no inherent limit on the range of the key length. The range is determined by the Cryptographic Service Provider which also determines the cryptographic algorithm.


This example sets the password encryption options for the active workbook.

Visual Basic for Applications
Sub SetPasswordOptions()

    ActiveWorkbook.SetPasswordEncryptionOptions _
        PasswordEncryptionProvider:="Microsoft RSA SChannel Cryptographic Provider", _
        PasswordEncryptionAlgorithm:="RC4", _
        PasswordEncryptionKeyLength:=56, _

End Sub
Bb178065.vs_note(en-us,office.12).gif  Note
The code and this method do not do anything for the new Excel file formats (xlsx, xlsb, xlsm, etc...) as the workbook will always use AES 128 bit encryption. If a property is set using this method, it will appear set. When the file is reloaded, the properties will be reset to the AES setting.