Private Sub Workbook_Open()
Dim strPassword As String '保存密码
Dim i As Integer '输入密码的次数
Do
strPassword = InputBox("请输入密码") '输入密码
If strPassword = "123" Then '判断密码是否正确
Exit Do '退出循环
Else
MsgBox ("请输入正确的密码!")
End If
i = i + 1
Loop While i < 3
If i >= 3 Then
ActiveWorkbook.Close
Else
Application.EnableEvents = False
End If
End Sub