Featured Post

Create Login Window with Username and Password In Excel

Excel VBA has quite interesting features which makes excel more powerful. I am covering different excel vba features through my tutorials in this page. In this tutorial we will cover how to make login window for excel sheets. You might think that excel itself has protection so why we use VBA based password protection. Here is answer! In Excel base protection any one can view your calculation data inside all sheets and can take screenshots which is not good at all. Excel protection only ask for password and don't require any username Through this tutorial you will learn how to make customized login window for your excel sheets. The code you will learn in this tutorial has following features.
  • Doesn't allow to view sheets.
  • Doesn't allow to click on any option of excel sheet
  • Doesn't allow to copy any data from any sheet.
  • Password is hidden in asterisk ("*")
  • Allow to quick change username and password without editing VBA
  • Hidden storage of your username and password

Follow below steps to design excel based login window

  • Create two sheets Main sheet and Database sheet (Optional)
  • Database sheet is sheet where your passwords are stored and edit new passwords
  • In VBA editor, Goto insert and insert two userforms as shown in figures
    • Userform1 will be for login window
    • Userform2 will be for Password Editing/Modification

  • In Userform1, Define Two TextBox 1 and 2 for username and password for login and Two CommandButtons for login and closing excel workbook. Incase if you don't have password you can't close workbook. The login window will disable all close, minimize etc options so you need to define button which close workbook. 
  • In Userform2, Define Two TextBox 1 and 2 for new username and password and One CommandButton to confirm new password.
  • Rename the TextBox1 as username and TextBox2 as password in both Userforms
  • In Textbox2 i.e Password box go to properties=>Alphabetic PasswordChar and define ("*") so that password could be shown in asterisk instead of visible password

Login Window Code
  • Write following code inside Userform1 Command Button (Login Button)
  • Write following code inside Userform1 Command Button 2 (Close Workbook Button) to close workbook if don't have password
    • ActiveWorkbook.Close
  • The third part of code is for disabling close option of Login Window if you don't disable anyone can close login window and can access your sheets
Change Password Window Code
  • Define two textbox in Database sheet from Developer=>Insert =>ActiveXControl textBox
  • These textboxes are for saving your new username and password 
  • Inside Change password button in Change Password Window Write below code
    • ActiveSheet.TextBox1.Value = UserForm2.TextBox1.Value
    • ActiveSheet.TextBox2.Value = UserForm2.TextBox2.Value
  • In the end VBA editor there is always ThisWorkbook sheet is created for defining workbook properties so write down below code inside ThisWorkbook
  • When workbook is opened it will load userform1 which is login window
  • In Database sheet, Change Password button write
           Private Sub CommandButton1_Click()
               UserForm2.Show
           End Sub
This code will load Change password window for changing password

Download Excel File: Download Here

Watch Complete Tutorial on YouTube



#computertech #computertechtutorial #loginwindowinexcel

Comments