SetPasswordEncryptionOptions Method

Microsoft Excel Visual Basic

SetPasswordEncryptionOptions Method

       

Sets the options for encrypting workbooks using passwords.

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

expression   Required. An expression that returns one of the objects in the Applies To list.

PasswordEncryptionProvider  Optional Variant. A case sensitive string of the encryption provider.

PasswordEncryptionAlgorithm  Optional Variant. A case sensitive string of the algorithmic short name (i.e. "RC4").

PasswordEncryptionKeyLength  Optional Variant. The encryption key length which is a multiple of 8 (40 or greater).

PasswordEncryptionFileProperties  Optional Variant. True (default) to encrypt file properties.

Remarks

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.

Example

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

Sub SetPasswordOptions()

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

End Sub