Notifications
Clear all

Userform Login e Planilhas Restritas

3 Posts
2 Usuários
0 Reactions
813 Visualizações
(@brunoafs)
Posts: 195
Reputable Member
Topic starter
 

Bom dia,

Andei lendo muito e achei um código que era exatamente o que pretendo,
Fiz umas adaptações porém não consigo fazer ele rodar.

Módulo 1 coloquei esses códigos conforme orientado.

Opition Explicit
Function VerifSenha(txtLogin As String, txtSenha As String) As Boolean

VerifSenha = False

Select Case txtLogin

    Case "ADMIN"

        If txtSenha = "xxx" Then VerifSenha = True

    Case "BRUNOAFS"

        If txtSenha = "xxx" Then VerifSenha = True

    Case Else

        MsgBox "O nome do usuário digitado não existe. Favor verificar."

End Select
End Function

Sub AcessoRestrito()

Dim Ws As Worksheet, Planilhas(), Pos As Integer

Select Case txtLogin

    Case "BRUNOAFS"
    
        Planilhas = Array("Inicial")
        On Error Resume Next
        For Each Ws In ThisWorkbook.Worksheets
        
            Pos = Application.Match(Ws.Name, Planilhas, 0)
                
                If Pos <> 0 Then
                    
                    Ws.Visible = True
                    Pos = 0
                
                Else
                
                    Ws.Visible = xlSheetVeryHidden
                    Pos = 0
                    
                End If
                
            Next Ws
            
    Case "ADMIN"
    
        For Each Ws In ThisWorkbook.Worksheets
        
            Ws.Visible = True
        
        Next Ws
            
    Case Else
    
        MsgBox "O usuário retorna um erro fatal", vbCritical
        
End Select
End Sub

No botão de "ENTRAR" na UserForm eu coloquei assim:

Private Sub BotãoEntrar_Click()

If txtLogin = "" Then
    MsgBox "Entrada de nome do usuário obrigatória.", vbInformation
    Exit Sub
End If

If txtSenha = "" Then
    MsgBox "Entrada de senha do usuário obrigatória.", vbInformation
    Exit Sub
End If

If VerifSenha = False Then

    MsgBox "Erro de Senha e/ou usuário. Favor digitar novamente.", vbInformation

    txtLogin = ""
    txtSenha = ""

    Exit Sub
End If

AcessoRestrito txtLogin

Unload frmLogin

End Sub

Porém não funciona.

Erro na linha: "If VerifSenha = False Then"

 
Postado : 27/10/2014 8:42 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Enquanto o pessoal não responde, poste seu arquivo modelo!!!

Att

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 27/10/2014 8:48 am
(@brunoafs)
Posts: 195
Reputable Member
Topic starter
 

Bom dia,

Segue anexo do modelo.

 
Postado : 27/10/2014 9:28 am