Word) (Document.Unprotect 方法

從指定的檔中移除保護。 .

語法

運算式取消保護 (密碼)

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

參數

名稱 必要/選用 資料類型 描述
Password 選用 Variant 用來保護文件的密碼字串。 這些密碼會區分大小寫。 如果文件使用密碼保護,但未輸入正確的密碼,就會顯示一個對話方塊,提示使用者輸入密碼。

安全性

重要事項

Avoid using hard-coded passwords in your applications. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code. 如需如何執行這項操作的建議最佳做法,請參閱 Office 解決方案開發人員的安全性注意事項

註解

如果文件未受到保護,這個方法就會產生錯誤。

範例

這則範例會使用 strPassword 變數值做為密碼,移除使用中文件的保護。

If ActiveDocument.ProtectionType <> wdNoProtection Then 
 ActiveDocument.Unprotect Password:=strPassword 
End If

這則範例會移除使用中文件的保護。 然後便插入文字,並針對修訂保護文件。

Set aDoc = ActiveDocument 
If aDoc.ProtectionType <> wdNoProtection Then 
 aDoc.Unprotect 
 Selection.InsertBefore "department six" 
 aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword 
End If

另請參閱

Document 物件

支援和意見反應

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