tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,832
- Office Version
- 365
- 2019
- Platform
- Windows
Can somone please test this for me. It works fine on my PC but not on others.
In Sheet2, cells A1 and A2, put some text. Then run the ThisWorkbook code.
It seems to crash for my users when it tries to retrieve the password:
ThisWorkbook:
ModFunctions:
ClsVariables:
In Sheet2, cells A1 and A2, put some text. Then run the ThisWorkbook code.
It seems to crash for my users when it tries to retrieve the password:
Code:
.Unprotect Password:=MyPassword.Password
ThisWorkbook:
Code:
Option Explicit
Dim PasswordArray() As Variant
Public Sub Workbook_Open()
With Me
Call .SetPassword
Call .UsersList
End With
Set MyAuthorisedUser = New ClsVariables
MyAuthorisedUser.AuthorisedUser = False
Dim PasswordElementsCounter As Integer
For PasswordElementsCounter = LBound(PasswordArray, 1) To UBound(PasswordArray, 1)
If ModFunctions.GetUsername = PasswordArray(PasswordElementsCounter, 1) Then
MyAuthorisedUser.AuthorisedUser = True
Exit For
End If
Next PasswordElementsCounter
With Sheet1
.Unprotect Password:=MyPassword.Password
.Protect Password:=MyPassword.Password
End With
Erase PasswordArray()
End Sub
Sub SetPassword()
Set MyPassword = New ClsVariables
MyPassword.Password = ModFunctions.GetUsername
End Sub
Sub UsersList()
PasswordArray = Sheet2.Cells(1, 1).CurrentRegion.Value
End Sub
ModFunctions:
Code:
Option Explicit
Global MyAuthorisedUser As ClsVariables
Global MyPassword As ClsVariables
Function GetUsername() As String
GetUsername = LCase(String:=Environ("UserName"))
End Function
ClsVariables:
Code:
Option Explicit
Private pAuthorisedUser As Boolean
Private pPassword As String
Public Property Get AuthorisedUser() As Boolean
AuthorisedUser = pAuthorisedUser
End Property
Public Property Let AuthorisedUser(ByVal AUser As Boolean)
pAuthorisedUser = AUser
End Property
Public Property Get Password() As String
Password = pPassword
End Property
Public Property Let Password(ByVal PWord As String)
pPassword = PWord
End Property