0% found this document useful (0 votes)
15 views3 pages

vba Code

The document is a VBA code for a user login form that checks for empty username and password fields before attempting to log in. It validates user credentials against data in an Excel sheet and displays appropriate messages for success or failure. The form also includes functionalities for changing the password visibility and handling form initialization and closure events.

Uploaded by

Samuel Bute
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

vba Code

The document is a VBA code for a user login form that checks for empty username and password fields before attempting to log in. It validates user credentials against data in an Excel sheet and displays appropriate messages for success or failure. The form also includes functionalities for changing the password visibility and handling form initialization and closure events.

Uploaded by

Samuel Bute
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Option Explicit

Private Sub buttonlogar_Click()

If txtUsuario = Empty Then

MsgBox "Digite o Usuario.", , "Usuario não digitado"

Exit Sub

End If

If txtSenha = Empty Then

MsgBox "Digite a Senha.", , "Senha não digitada"

Exit Sub

End If

Call Logar(txtUsuario, txtSenha)

End Sub

Private Sub buttonlogar_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As


Single, ByVal Y As Single)

buttonlogar.Font.Bold = True

End Sub

Private Sub txtSenha_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

txtSenha.PasswordChar = "*"

End Sub

Private Sub txtSenha_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single,
ByVal Y As Single)

txtSenha.PasswordChar = ""

End Sub
Private Sub txtSenha_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single,
ByVal Y As Single)

txtSenha.PasswordChar = "*"

End Sub

Private Sub Logar(Usuario As String, Senha As String)

Dim Linha As Integer

Linha = 2

Do Until Sheet2.Cells(Linha, 1) = Empty

If Sheet2.Cells(Linha, 2) = Usuario And Sheet2.Cells(Linha, 3) = Senha Then

MsgBox "Logado com sucesso"

Unload Login

Application.Visible = True

Exit Sub

End If

Linha = Linha + 1

Loop

MsgBox "Usuario não encontrado."

End Sub

Private Sub UserForm_Initialize()

Application.Visible = False

End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As
Single, ByVal Y As Single)

buttonlogar.Font.Bold = False

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If CloseMode = 0 Then

ThisWorkbook.Save

ThisWorkbook.Close

End If

End Sub

You might also like