Document.Password property (Word)
Sets a password that must be supplied to open the specified document. Write-only String.
Syntax
expression. Password
expression A variable that represents a Document object.
Remarks
Important
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. For recommended best practices on how to do this, see Security notes for Office solution developers.
Example
This example opens Earnings.doc, sets a password for it, and then closes the document.
Set myDoc = Documents _
.Open(FileName:="C:\My Documents\Earnings.doc")
myDoc.Password = strPassword
myDoc.Close
See also
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.
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: Under hela 2024 kommer vi att fasa ut GitHub-problem som feedbackmekanism för innehåll och ersätta det med ett nytt feedbacksystem. Mer information finns i:Skicka och visa feedback för