Word () Document.SetPasswordEncryptionOptions 方法

設定 Microsoft Word 用來以密碼加密文件的選項。

語法

運算式SetPasswordEncryptionOptions( _PasswordEncryptionProvider_ , _PasswordEncryptionAlgorithm_ , _PasswordEncryptionKeyLength_ , _PasswordEncryptionFileProperties_ )

需要 expression。 代表 Document 物件的變數。

參數

名稱 必要/選用 資料類型 描述
PasswordEncryptionProvider 必要 String 加密提供者的名稱。
PasswordEncryptionAlgorithm 必要 String 加密演算法的名稱。 Word 支援資料流加密的演算法。
PasswordEncryptionKeyLength 必要 Long 加密金鑰長度。 它必須是 8 的倍數,從 40 開始。
PasswordEncryptionFileProperties 選用 Variant True 是表示 Word 在加密檔案屬性。 預設值為 True

註解

為了增強安全性,請勿使用弱式加密 (XOR) (也稱為 「OfficeXor」) 或 「Office97/2000 Compatible」 (也稱為 「OfficeStandard」) 演算法。

範例

如果目前使用中的密碼加密演算法是 "OfficeXor" 或 "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

另請參閱

Document 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應