Here's the Excel VBA code allow specific users to access the Excel file. Other users can open it in read-only mode.
However, other users can still click once to enter edit mode to edit.
I want the Excel VBA to allow specific users to open excel file, while other users need to enter password and cannot see what are the contents before they entered correct password.
Is is possible to achieve that?
Many thanks for your help!
Code: Select all
Private Sub Workbook_Open()
Dim Users As String
Dim Password As String
Users = Environ("USERNAME")
Password = InputBox("Enter password to access this workbook", "Password Required")
Select Case Users
Case "user1": MsgBox "ok"
Case "user2": MsgBox "ok"
Case "user3": MsgBox "ok"
Case Else
If Password = "your_password" Then
ThisWorkbook.ChangeFileAccess xlReadWrite
Else
ThisWorkbook.ChangeFileAccess xlReadOnly
End If
End Select
End Sub