April 2006
Beginner
1114 pages
98h 16m
English
workbook.Password [= setting]
Sets a password used to open the workbook. Returns "********" whether or not a password was previously set. The following code sets a password entered by the user in an InputBox:
Dim wb As Workbook, pass As String
Set wb = ThisWorkbook
pass = InputBox("Enter a password.", "Password")
If pass = "" Then Exit Sub
If pass = InputBox("Enter password again to confirm.", "Password") Then
wb.Password = pass
MsgBox "Password set.", , "Password."
Else
MsgBox "Passwords don't match. No password set.", , "Password"
End IfThe InputBox displays characters as they are typed. It is a better idea to use a user form with text boxes that display a password character to get passwords from users.
Read now
Unlock full access