How to Create a Login Window to Protect Excel Workbook and recorde login

AT BABU

Board Regular
Joined
Oct 12, 2018
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hi folks,

Thank you for you support.

I have search in google i find below from this sit(
https://www.datanumen.com/blogs/create-login-window-protect-excel-workbook/)

but it not suitable for me. Because of have 30 users and this code very long and user login not recode so. Please help me this Marco


Private Sub CommandButton1_Click()
If TextBox1.Value = "" Then
If TextBox2.Value = "" Then
MsgBox "Please Input the User Name and the Password"
Else
MsgBox "Please Input the User Name"
End If
ElseIf TextBox1.Value = "Admin" Then
If TextBox2.Value = "" Then
MsgBox "Please Input the Password"
ElseIf TextBox2.Value = "123" Then
Me.Hide: Application.Visible = True
Else
MsgBox "Please Input the right User Name and the right Password"
End If
Else
If TextBox2.Value = "" Then
MsgBox "Please Input the Password"
Else
MsgBox "Please Input the right User Name and the right Password"
End If
End If
End Sub


Private Sub CommandButton2_Click()
ThisWorkbook.Application.Quit
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
ThisWorkbook.Application.Quit
End Sub



 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

From same Site you Have Linket too

Code:
Private Sub CommandButton1_Click()
  Dim objTargetWorksheet As Worksheet

  If (TextBox1.Value = "Admin" And TextBox2.Value = "123") _
    Or (TextBox1.Value = "Support" And TextBox2.Value = "234") _
    Or (TextBox1.Value = "Super" And TextBox2.Value = "345") Then
    Me.Hide: Application.Visible = True
    For Each objTargetWorksheet In ActiveWorkbook.Worksheets
      If objTargetWorksheet.Name = TextBox1.Value Then
        objTargetWorksheet.Unprotect Password:=Test
      Else
        objTargetWorksheet.Protect Password:=Test, DrawingObjects:=True, Contents:=True, Scenarios:=True
      End If
    Next
  Else
    MsgBox "Please input the right user name and the right password"
  End If
End Sub
Private Sub CommandButton2_Click()
  ThisWorkbook.Application.Quit
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  ThisWorkbook.Application.Quit
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top