Share via


Document.SetPasswordEncryptionOptions Method

Word Developer Reference

Sets the options Microsoft Word uses for encrypting documents with passwords.

Syntax

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

expression   Required. A variable that represents a Document object.

Parameters

Name Required/Optional Data Type Description
PasswordEncryptionProvider Required String The name of the encryption provider.
PasswordEncryptionAlgorithm Required String The name of the encryption algorithm. Word supports stream-encrypted algorithms.
PasswordEncryptionKeyLength Required Long The encryption key length. Must be a multiple of 8, starting at 40.
PasswordEncryptionFileProperties Optional Variant True for Word to encrypt file properties. Default is True.

Remarks

For enhanced security, do not use Weak Encryption (XOR) (also called "OfficeXor") or "Office97/2000 Compatible" (also called "OfficeStandard") algorithms.

Example

This example sets the password encryption to a stronger encryption if the password encryption algorithm in use is "OfficeXor" or "OfficeStandard."

Visual Basic for Applications
  Sub PasswordSettings()
    With ActiveDocument
        If .PasswordEncryptionAlgorithm = "OfficeXor" Or _
                .PasswordEncryptionAlgorithm = "OfficeStandard" Then
        .SetPasswordEncryptionOptions _
            PasswordEncryptionProvider:="Microsoft RSA SChannel Cryptographic Provider", _
            PasswordEncryptionAlgorithm:="RC4", _
            PasswordEncryptionKeyLength:=56, _
            PasswordEncryptionFileProperties:=True

    End If
End With

End Sub

See Also