Is it possible in some way to have access to windows credentials, to know which user wants to occupy the file and thus facilitate or deny access ?. I have a code that searches for the user and according to that gives or removes access, but it seems unreliable. The code is the following:
Private Sub Workbook_Open()
ThisWorkbook.Windows(1).Visible = False
Application.DisplayAlerts = False
If Application.UserName = "CMSTORM" Or Application.UserName = "User2" Then
Welc = MsgBox("Bienvenido " & Application.UserName)
ThisWorkbook.Windows(1).Visible = True
Application.DisplayAlerts = True
Exit Sub
Else
Pass = "1973"
Prompt = "Ingresa la contraseña para continuar"
Title = "Ingreso de Contraseña"
UserPass = InputBox(Prompt, Title)
If UserPass <> Pass Then
Prompt = "Contraseña Incorrecta"
Title = "Contraseña Incorrecta"
MsgBox Prompt, vbCritical, Title
ThisWorkbook.Close
Exit Sub
Else
Welc = MsgBox("Bienvenido " & Application.UserName)
ThisWorkbook.Windows(1).Visible = True
Application.DisplayAlerts = True
End If
End If
End Sub