Excel file is very essential for your work. Therefore, here we will introduce you a method to create a login window for your Excel files.
It is unavoidable that you need to lend your computer to other people. And you will certainly want to prevent other people from viewing your Excel files. There are several methods you can do to protect your files. For instance, you can hide your files, or you can set password for your files. Besides, in this article, you can also learn how to create a login window for your Excel files. And now follow the steps in the coming parts.
Create a Login Window
- Press the shortcut keys “Alt +F11” on the keyboard to open the Visual Basic editor.
- And then insert a user form in the editor.
- In this new form, add two labels, two text boxes and two buttons.
- And then change the captions for the user form, two labels and two buttons. You can also refer to the image below to change the captions.
- After that, click the text box for password.
- Change the password char into “*” for this text box.
- Double click the user form.
- And then input the following codes into the module:
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
These macros will consist of the main part of the login window. You need to change the name and the password according to your actual need.
- And then double click the “ThisWorkbook” in the VBA projector.
- Input the following codes into the editor.
Private Sub Workbook_Open() Application.Visible = False: UserForm1.Show End Sub
- In the end, save the file as a macro-enabled file in your computer.
- Now open the file again, at this time, the user form will not appear. Instead, you will see the “Security warning”.
- Here click the “Enable Content”. And then you will see the login window pop up.
The next time you open the file, you will always be asked to input the name and the password. Therefore, you will never need to worry that someone else will open your files.
All Type of Storage will Meet with Accidents
When you store data and information in Excel files, you still need to pay attention on your files. There is no one type of storage that is fully secure. Therefore, you need to take certain measures. Once you meet with Excel corruption, you can repair Excel xlsx data problem with a powerful tool. This tool can help you get back all the information in damaged files.
Anna Ma is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair Word docx data and outlook repair software products. For more information visit www.datanumen.com