Muokkaa

Jaa


Document.SetPasswordEncryptionOptions method (Word)

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, don't 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."

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

Document Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.