设置使用密码加密工作簿的选项。
语法
表达式。SetPasswordEncryptionOptions (PasswordEncryptionProvider、 PasswordEncryptionAlgorithm、 PasswordEncryptionKeyLength、 PasswordEncryptionFileProperties)
表达式 表示 工作簿 对象的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 说明 |
|---|---|---|---|
| PasswordEncryptionProvider | 可选 | Variant | 加密提供程序的字符串(区分大小写)。 |
| PasswordEncryptionAlgorithm | 可选 | Variant | 区分大小写的算法短名称 (字符串,即“RC4”) 。 |
| PasswordEncryptionKeyLength | 可选 | Variant | 加密密钥的长度,为 8 的倍数(40 或更大)。 |
| PasswordEncryptionFileProperties | 可选 | Variant | 如果为 True(默认值),则加密文件属性。 |
备注
PasswordEncryptionProvider、PasswordEncryptionAlgorithm 和 PasswordEncryptionKeyLength 参数不相互独立。 选定的加密提供商限制了可以选择的算法和密钥长度的设置。
对于 PasswordEncryptionKeyLength 参数,密钥长度的范围没有固有限制。 范围由加密服务提供商确定,而加密服务提供商还决定加密算法。
示例
本示例设置活动工作簿的密码加密选项。
Sub SetPasswordOptions()
ActiveWorkbook.SetPasswordEncryptionOptions _
PasswordEncryptionProvider:="Microsoft RSA SChannel Cryptographic Provider", _
PasswordEncryptionAlgorithm:="RC4", _
PasswordEncryptionKeyLength:=56, _
PasswordEncryptionFileProperties:=True
End Sub
注意
代码和此方法对于新的 Excel 文件格式 (xlsx、xlsb、xlsm 等不执行任何操作 ) 因为工作簿将始终使用 AES 128 位加密。 如果使用此方法设置了属性,则显示为已设置。 重新加载文件时,属性将重置为 AES 设置。
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。