Name

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

Synopsis

Sets the workbook’s encryption properties.

Argument

Settings

PasswordEncryptionProvider

A string containing the full name of the encryption provider, such as "OfficeStandard" for no encryption or "Microsoft Base Cryptographic Provider v1.0".

PasswordEncryptionAlgorithm

A string containing the type of encryption to use. Use "Office" for no encryption, "RC4" for encryption.

PasswordEncryptionKeyLength

The length of the encryption key. Must be a valid value for the encryption provider.

PasswordEncryptionFileProperties

Set to True to encrypt the workbook’s file properties, False to leave them unencrypted.

The following code sets strong encryption on a workbook:

    Set wb = ThisWorkbook
    wb.SetPasswordEncryptionOptions "Microsoft Strong Cryptographic Provider", _
      "RC4", 128, True

Get Programming Excel with VBA and .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.