Word) (Document.Password 屬性

設定必須提供開啟指定的文件的密碼。 唯寫的 字串

語法

expressionPassword

表達 代表 Document 物件的變數。

註解

重要事項

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 解決方案開發人員的安全性注意事項

範例

本範例會開啟 Earnings.doc、為其設定密碼,然後關閉此文件。

Set myDoc = Documents _ 
 .Open(FileName:="C:\My Documents\Earnings.doc") 
myDoc.Password = strPassword 
myDoc.Close

另請參閱

Document 物件

支援和意見反應

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