Second post here. All I want to do is change the password to protect and unprotect my workbook as defined in my code here...
Dim myPassword As String
myPassword = "yogurt" 'defines the password
For Each sh In ActiveWorkbook.Worksheets 'unprotects the sheet for editing
sh.Unprotect Password:=myPassword
Next sh
...by using another macro called something like "Change password," wherein the user would enter the current password and then be able to enter the new password.
I only want the "change password" macro to work if the user types the new password twice to ensure accuracy.
any quick suggestions?
Many thanks.
Sub change_password()
Dim OldPassword, MyPassword, NewPassword As String
Dim pass1, pass2
MyPassword = monkey
OldPassword = InputBox("Please enter the old password.")
If OldPassword = MyPassword Then
pass1 = InputBox("Enter the new password.")
pass2 = InputBox("Enter the new password again to ensure accuracy.")
If pass1 = pass2 Then
MyPassword = pass1
Else
MsgBox "The new password you entered was not entered correctly both times."
End If
End If
MsgBox ("Your new password is" & MyPassword)
End Sub