第二个帖子在这里。我要做的就是更改密码以保护和取消保护我的工作簿,如我在此处的代码中定义的那样......
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
...通过使用另一个称为“更改密码”的宏,其中用户将输入当前密码,然后能够输入新密码。
如果用户输入两次新密码以确保准确性,我只希望“更改密码”宏起作用。
有什么快速的建议吗?
非常感谢。
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