Ad Clicks : Ad Views :
Excel formulas and tutorials

Excel formulas and useful tools


  1. Dear Ravindra,

    You’re welcome!
    In the cmdOK_Click() procedure you can insert a query from a database or, if you want to keep it static, you can add more users and passwords in this procedure:
    if strconv(trim(……..)=”GUEST” or strconv(trim(…..)=”GUEST2″ then
    if strconv(trim(……)=”PA$$” or strconv(trim(……..)=”PA$$2″ then

    This is it!
    Kind regards!

    • do you have macros enabled? does the login form appear?
      use credentials guest and pa$$

      to view the VBA code use PA$$

  2. Hello sir, it is very usefull. I want to change user id, how can we do that. I also couldn’t understand where to paste multiple user login codes. Please help

  3. Okk. I found it. But it also allow “Guest1” with the Password of “Guest2” and vice versa. Any solution?

    • Hi Rajat,

      Sorry for the late reply.
      I amended and replaced the xlsm file, so now a list of users and passwords could be accommodated inside sheet Usr. Please open the VBA editor (PA$$) and set the visible attribute to Visible. When you save the file, this sheet will get VeryHidden so that it will not be available for anyone.

    • Hi Ramlee,

      Be sure you have set the visibility property to “visible” for the Usr sheet in the VBA editor. There are 3 user defined.

  4. Dear Sir

    Thank you so much for making this available (new to VBA), much appreciated. I need to restrict some sheets in the workbook, eg HR department can only see their HR sheet. Would it be possible for you to give me guidance how to add this to your template?

    Kind Regards

    Martie Snyders

    • Hi Martie,

      You have to add department code to each user in the usr sheet (which is very hidden) and use this code in the login module:

      Private Sub cmdOK_Click()
      Dim j As Integer

      j = 2
      found = 0
      While Sheets(“Usr”).Cells(j, 1) <> “” And found = 0
      department = “”
      If Sheets(“Usr”).Cells(j, 2) = Trim(txtName.Text) And Sheets(“Usr”).Cells(j, 3) = txtPassword.Text Then
      found = 1
      department = Sheets(“Usr”).Cells(j, 4)
      Unload Me
      End If
      j = j + 1
      If department = “HR” Then
      Sheets(“HR”).Visible = xlSheetVisible
      Sheets(“HR”).Visible = xlSheetVeryHidden
      End If

      If found = 0 Then
      MsgBox “Wrong user name or password!”, vbCritical, “Error”
      End If

      End Sub

Leave a Comment

Your email address will not be published. Required fields are marked *

It is main inner container footer text