使用VBA的密码保护工作簿无法正常工作

时间:2019-06-13 10:41:05

标签: excel vba

我创建了一个工作簿,只能由几个人访问。 下面的代码已放置在工作簿中。 有一个userform,其中两个textboxes,一个用于用户名,一个用于密码。

然后我对照在VBA中创建的条目检查这些条目。但是,它仅适用于一个人,而不适用于另一个人。

RossName和Ross密码允许我访问工作簿,但是GulsenName和GulsenPassword不允许。它将返回"ELSE"函数并显示MsgBox,所以是假的吗?我想念什么? 谢谢您的帮助。

Private Sub CommandButton2_Click()
    Dim enteredUserName  As String
    Dim GulsenName As String
    Dim RossName As String
    Dim enteredpassword As String
    Dim gulsenPassword As String
    Dim RossPassword As String

    RossName = "RossA"
    RossPassword = "Password1"
    GulsenName = "Gulsen"
    gulsenPassword = "Password2"

    enteredUserName = Me.TextBox1.Text
    enteredpassword = Me.TextBox2.Text

    If (enteredUserName = RossName Or enteredpassword = GulsenName) And (enteredpassword = RossPassword Or enteredpassword = gulsenPassword) Then
        Worksheets(1).Select
        Unload Me
    Else        
        MsgBox ("userName or Password incorrect, please try again")
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

AND 更改为 OR

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="sortcon">
  <button id="offerdown">
  sortofferup
  </button>
  <button id="offerup">
  sortofferdown
  </button>

  <div id="allbdcontainer">

    <div class="bdcontainer">

      <div class="clear">
      </div>

      <div class="bdshowfromdate">01.11.2018
      </div>

      <div class="seperator">-
      </div>

      <div class="bdshowtodate">31.12.2025
      </div>

      <div class="bdshowoffer">P3
      </div>

    </div>

    <div class="bdcontainer">

      <div class="clear">
      </div>

      <div class="bdshowfromdate">01.11.2018
      </div>

      <div class="seperator">-
      </div>

      <div class="bdshowtodate">31.12.2019
      </div>

      <div class="bdshowoffer">P1D
      </div>

    </div>

    <div class="bdcontainer">

      <div class="clear">
      </div>

      <div class="bdshowfromdate">15.10.2018
      </div>

      <div class="seperator">-
      </div>

      <div class="bdshowtodate">20.10.2018
      </div>

      <div class="bdshowoffer">P2V
      </div>

    </div>

    <div class="bdcontainer">

      <div class="clear">
      </div>

      <div class="bdshowfromdate">15.10.2018
      </div>

      <div class="seperator">-
      </div>

      <div class="bdshowtodate">28.10.2018
      </div>

      <div class="bdshowoffer">P2V
      </div>

    </div>

    <div class="bdcontainer">

      <div class="clear">
      </div>

      <div class="bdshowfromdate">07.08.2019
      </div>

      <div class="seperator">-
      </div>

      <div class="bdshowtodate">04.09.2019
      </div>

      <div class="bdshowoffer">P1D
      </div>

    </div>

    <div class="bdcontainer">

      <div class="clear">
      </div>

      <div class="bdshowfromdate">22.03.2020
      </div>

      <div class="seperator">-
      </div>

      <div class="bdshowtodate">25.03.2020
      </div>

      <div class="bdshowoffer">P2I
      </div>

    </div>
  </div>