Hi Guys, I hope you can help me this time
I have a login window create with a vba form and when the user close this workbook clicking on "X" button or cancel, the macro used makes all workbooks open, turn close automatically. The goal is that the macro only close the workbook with the vba form. The code is the following:
Code for "Login" button
Private Sub CommandButton1_Click()
If Trim(txtUser.Text) = "" Then
MsgBox "Enter user", vbExclamation, "Warning"
txtUser.SetFocus
Exit Sub
End If
If Trim(txtPass.Text) = "" Then
MsgBox "Enter password", vbExclamation, "Warning"
txtPass.SetFocus
Exit Sub
End If
If Trim(txtUser.Text) = "USER" And Trim(txtPass.Text) = "PASSWORD" Then
MsgBox "Access allowed", vbInformation, "Input Data"
Application.Visible = True
ThisWorkbook.salida = 2
'Unload Me
'MsgBox "The data entered is correct"
End
Else
MsgBox "The data entered is incorrect, try again", vbExclamation, "Warning"
End If
End Sub
Code for "Cancel" button
Private Sub CommandButton2_Click()
ThisWorkbook.salida = 1
Unload Me
'MsgBox "CANCEL key pressed, exit without recording"
ThisWorkbook.Close savechanges:=False
End Sub
Code for "X" button
Private Sub UserForm_Terminate()
If ThisWorkbook.salida = 0 Then
ThisWorkbook.salida = 1
Unload Me
'MsgBox "X key pressed, exit without recording"
ThisWorkbook.Close savechanges:=False
End If
LOGIN.png
NOTE: This macro is composed to other macros in the private mood to obligate to the user to "enable the use of the macros". All of this makes the first time the user after enter the correct data and access to the workspacet, only see a "Welcome Page" and then when the user enable the macros see all the sheets hide.
Bookmarks