Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 在打开书本之前检测外部用户并询问密码_Excel_Vba - Fatal编程技术网

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

Excel 在打开书本之前检测外部用户并询问密码,excel,vba,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)

我正在尝试制作一个简短的代码,以便它能够检测到外部用户并请求密码,但我不知道如何避免保存消息

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
Private子工作簿\u Open()
ThisWorkbook.Windows(1).Visible=False
如果Application.UserName=“User1”或Application.UserName=“User2”,则
Welc=MsgBox(“欢迎”和Application.UserName)
ThisWorkbook.Windows(1).Visible=True
出口接头
其他的
Pass=“1973”
Prompt=“输入密码以继续”
Title=“密码输入”
UserPass=InputBox(提示,标题)
如果用户通过,那么
Prompt=“您输入的密码不正确”
Title=“不正确的密码”
MsgBox提示符,vbCritical,标题
此工作簿。关闭
出口接头
其他的
Welc=MsgBox(“欢迎”和Application.UserName)
ThisWorkbook.Windows(1).Visible=True
如果结束
如果结束
端接头

我不知道
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
Private子工作簿\u Open()
ThisWorkbook.Windows(1).Visible=False
Application.DisplayAlerts=False
如果Application.UserName=“User1”或Application.UserName=“User2”,则
Welc=MsgBox(“欢迎”和Application.UserName)
ThisWorkbook.Windows(1).Visible=True
Application.DisplayAlerts=True
出口接头
其他的
Pass=“1973”
Prompt=“输入密码以继续”
Title=“密码输入”
UserPass=InputBox(提示,标题)
如果用户通过,那么
Prompt=“您输入的密码不正确”
Title=“不正确的密码”
MsgBox提示符,vbCritical,标题
此工作簿。关闭
出口接头
其他的
Welc=MsgBox(“欢迎”和Application.UserName)
ThisWorkbook.Windows(1).Visible=True
Application.DisplayAlerts=True
如果结束
如果结束
端接头

为什么不使用Excel的内置密码进行访问?这是否检测到用户?我只是经常用它来询问密码。我想这个板上评级为1k或更高的人几乎都可以绕过你的“安全”。在打开时禁用宏。。。用纯文本写的。。。也许你的网站没有与非常老练的用户打交道,所以它可能会起作用。但是,如果您认真地试图阻止某些数据或文件,则不应认为此方法是可靠的。我不是在与宏用户打交道,但这是我现在唯一的方法:(