control de acceso con excel

Upload: rild278111

Post on 16-Feb-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 Control de Acceso Con Excel

    1/6

    Hoja6 - 1Private Sub Worksheet_Activate()

    Sheets("INICIO").ScrollArea = ("A1:A10") Cambiauser.Show Modeless

    End Sub

  • 7/23/2019 Control de Acceso Con Excel

    2/6

    ThisWorkbook - 1Private Sub Workbook_BeforeClose(Cancel As Boolean) Call ocultaEnd Sub

    Private Sub Workbook_Open() Sheets("INICIO").ScrollArea = ("A1:A10") Call oculta UserForm1.ShowEnd Sub

  • 7/23/2019 Control de Acceso Con Excel

    3/6

    Cambiauser - 1

    'Option Explicit

    Const GWL_STYLE = -16

    Const WS_CAPTION = &HC00000Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd AsLong, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As LongPrivate Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    'Posicin del formularioDim FormX As Double, FormY As Double

    Private Sub CommandButton1_Click() Call oculta UserForm1.Show End Sub

    Private Sub CommandButton2_Click() Call CERRAREnd Sub

    Private Sub UserForm_Initialize() Dim lngWindow As Long, lFrmHdl As Long lFrmHdl = FindWindowA(vbNullString, Me.Caption) lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE) lngWindow = lngWindow And (Not WS_CAPTION) Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow) Call DrawMenuBar(lFrmHdl)End Sub

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

    If Button = 1 Then FormX = X FormY = Y End If

    End Sub

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

    If Button = 1 Then Me.Left = Me.Left + (X - FormX) Me.Top = Me.Top + (Y - FormY) End IfEnd Sub

    Private Sub CloseButton_Click()

    Unload MeEnd Sub

  • 7/23/2019 Control de Acceso Con Excel

    4/6

    UserForm1 - 1'Option Explicit

    Const GWL_STYLE = -16Const WS_CAPTION = &HC00000

    Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd AsLong, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As LongPrivate Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    'Posicin del formularioDim FormX As Double, FormY As Double

    Private Sub CommandButton1_Click()

    Call accesoEnd Sub

    Private Sub CommandButton2_Click() Call CERRAREnd Sub

    Private Sub UserForm_Initialize() Dim lngWindow As Long, lFrmHdl As Long lFrmHdl = FindWindowA(vbNullString, Me.Caption) lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE) lngWindow = lngWindow And (Not WS_CAPTION) Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow) Call DrawMenuBar(lFrmHdl) TextBoxU = "" TextBoxC = ""

    End SubPrivate Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single,ByVal Y As Single)

    If Button = 1 Then FormX = X

    FormY = Y End IfEnd Sub

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

    If Button = 1 Then Me.Left = Me.Left + (X - FormX) Me.Top = Me.Top + (Y - FormY) End IfEnd Sub

  • 7/23/2019 Control de Acceso Con Excel

    5/6

    Mdulo1 - 1Sub acceso()Dim TablaUsuarios As RangeDim usuario, clave As String

    On Error GoTo advr

    Sheets("INICIO").Activate Range("XFC1").Select

    Set TablaUsuarios = Range("XFC2:XFD5") usuario = UserForm1.TextBoxU clave = UserForm1.TextBoxC clavecorrecta = Application.WorksheetFunction.VLookup(usuario, TablaUsuarios, 2, False)

    If clavecorrecta clave Then GoTo advr

    If clave = "anax" Then Sheets("GONIOMETRICA").Visible = -1 Sheets("GONIOMETRICA").Activate Sheets("Grfico y=ax+bx+c").Visible = -1 ElseIf clave = "pepe" Then Sheets("SENO").Visible = -1 Sheets("SENO").Activate ElseIf clave = "rompe" Then Sheets("Sistema de 3 ecuaciones").Visible = -1 Sheets("Sistema de 3 ecuaciones").Activate ElseIf clave = "anac" Then Sheets("Grfico y=ax+b").Visible = -1 Sheets("Grfico y=ax+b").Activate End If Unload UserForm1Endadvr:Ouch = MsgBox("EL USUARIO, LA CLAVE O AMBOS" & Chr(13) _& "SON ERRONEOS", vbCritical)End Sub

    Sub oculta()

    Sheets("GONIOMETRICA").Visible = 2 Sheets("SENO").Visible = 2 Sheets("Sistema de 3 ecuaciones").Visible = 2 Sheets("Grfico y=ax+b").Visible = 2 Sheets("Grfico y=ax+bx+c").Visible = 2

    End Sub

    Private Sub muestra() Sheets("GONIOMETRICA").Visible = -1 Sheets("SENO").Visible = -1 Sheets("Sistema de 3 ecuaciones").Visible = -1

    Sheets("Grfico y=ax+b").Visible = -1 Sheets("Grfico y=ax+bx+c").Visible = -1End Sub

  • 7/23/2019 Control de Acceso Con Excel

    6/6

    Mdulo1 - 2

    Sub CERRAR() SIONO = MsgBox("SEGURO QUE QUIERE SALIR?", vbYesNo) If SIONO = vbYes Then

    Unload UserForm1 ActiveWorkbook.Close End IfEnd SubSub lanza_form() UserForm1.ShowEnd Sub