检测外部用户并在打开书籍之前询问密码

  • 本文关键字:密码 外部 用户 excel vba
  • 更新时间 :
  • 英文 :


我正在尝试制作一个短代码,以便它可以检测外部用户并要求输入密码,但我不知道如何避免保存消息。

Private Sub Workbook_Open()
ThisWorkbook.Windows(1).Visible = False
If Application.UserName = "User1" Or Application.UserName = "User2" Then
Welc = MsgBox("Welcome " & Application.UserName)
ThisWorkbook.Windows(1).Visible = True
Exit Sub
Else
Pass = "1973"
Prompt = "Enter the password to continue"
Title = "Password Input"
UserPass = InputBox(Prompt, Title)
If UserPass <> Pass Then
Prompt = "You have entered an incorrect password"
Title = "Incorrect Passowd"
MsgBox Prompt, vbCritical, Title
ThisWorkbook.Close
Exit Sub
Else
Welc = MsgBox("Welcome " & Application.UserName)
ThisWorkbook.Windows(1).Visible = True
End If
End If
End Sub

我不知道Application.DisplayAlerts = False

Private Sub Workbook_Open()
ThisWorkbook.Windows(1).Visible = False
Application.DisplayAlerts = False
If Application.UserName = "User1" Or Application.UserName = "User2" Then
Welc = MsgBox("Welcome " & Application.UserName)
ThisWorkbook.Windows(1).Visible = True
Application.DisplayAlerts = True
Exit Sub
Else
Pass = "1973"
Prompt = "Enter the password to continue"
Title = "Password Input"
UserPass = InputBox(Prompt, Title)
If UserPass <> Pass Then
Prompt = "You have entered an incorrect password"
Title = "Incorrect Passowd"
MsgBox Prompt, vbCritical, Title
ThisWorkbook.Close
Exit Sub
Else
Welc = MsgBox("Welcome " & Application.UserName)
ThisWorkbook.Windows(1).Visible = True
Application.DisplayAlerts = True
End If
End If
End Sub

最新更新