KyleJackMorrison
Board Regular
- Joined
- Dec 3, 2013
- Messages
- 107
- Office Version
- 365
- 2021
- 2019
- Platform
- Windows
Hello,
I have a code which unlocks a sheet based on usernames.
I've noticed that the code sometimes doesn't work because our Environ("UserName") changes from a Capital letter at the start to sometimes a lower case letter randomly.
For example,
"Morrisonk123" to "morrisonk123" This throws my code out and doesn't unlock the sheet as I have it set up to recognise the lowercase username.
Is there a way to get around this or do I have to put "Morrisonk123", "morrisonk123" just to be safe?
I have a code which unlocks a sheet based on usernames.
I've noticed that the code sometimes doesn't work because our Environ("UserName") changes from a Capital letter at the start to sometimes a lower case letter randomly.
For example,
"Morrisonk123" to "morrisonk123" This throws my code out and doesn't unlock the sheet as I have it set up to recognise the lowercase username.
Is there a way to get around this or do I have to put "Morrisonk123", "morrisonk123" just to be safe?
Code:
Sub xUnlock()
Dim sUser As String
Application.ScreenUpdating = False
sUser = Environ("UserName")
Select Case sUser
Case "morrisonk102", "user1", "user2"
Sheets("FOE Jan 19 - Dec 19").Unprotect Password:="11SQN4AMR"
MsgBox "Welcome " & Application.UserName & " the FOE has now been unlocked for editing.", vbOKOnly, "Welcome"
Case Else
Sheets("FOE Jan 19 - Dec 19").Protect Password:="11SQN4AMR"
End Select
Application.ScreenUpdating = True
End Sub