Results 1 to 3 of 3

Thread: Unprotect sheet for certain users upon start up

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Hey Georgiboy....

    I ended up getting it after a lot of trial and error right before you replied..This is the code that works for me.

    'This sets all users to read only unless you are listed in AuthUsers sheet column A
    Users = Environ("USERNAME")
    Set C = Worksheets("AuthUsers").Range("A1:A1000").Find(Users, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    If C Is Nothing Then
          Application.DisplayAlerts = False
          On Error Resume Next
          'may already be read only
         If ThisWorkbook.Path <> vbNullString Then ThisWorkbook.ChangeFileAccess xlReadOnly
         On Error GoTo 0
         Application.DisplayAlerts = True
    End If
    'This sets all users to protected mode unless in Admin Cell A3:A6
    ThisWorkbook.Worksheets("EDP #s").Unprotect (Pass)
    Users = Environ("USERNAME")
    Set C = Worksheets("AuthUsers").Range("A3:A6").Find(Users, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    If C Is Nothing Then
        Application.DisplayAlerts = False
        On Error Resume Next
        If ThisWorkbook.Path <> vbNullString Then ThisWorkbook.Worksheets("EDP #S").Protect (Pass)
        On Error GoTo 0
        Application.DisplayAlerts = True
    End If
    'This shows the AuthUsers Sheet to Admin users and hides to everyone else.
    Users = Environ("USERNAME")
    Set C = Worksheets("AuthUsers").Range("A3:A6").Find(Users, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    If C Is Nothing Then
         Application.DisplayAlerts = False
         On Error Resume Next
         If ThisWorkbook.Path <> vbNullString Then ThisWorkbook.Worksheets("AuthUsers").Visible = False
         On Error GoTo 0
         Application.DisplayAlerts = True
    End If
    Thank you for the help!
    Last edited by Aussiebear; 09-29-2023 at 01:11 PM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •