Results 1 to 4 of 4

Password Protecting each sheet for different users

Threaded View

  1. #1
    Registered User
    Join Date
    01-18-2023
    Location
    Michigan, USA
    MS-Off Ver
    Office16
    Posts
    2

    Post Password Protecting each sheet for different users

    Scenario:
    I have 1 workbook with 8 sheets. I only want certain people to be able to access each sheet to modify data. Here is where I am, but I cannot go further. It keeps giving this error Error.jpg marked in red below. Any suggestions?
    Private Sub Workbook_aftersave(ByVal Success As Boolean)
        UnprotectSheet
        ThisWorkbook.Saved = True
    End Sub
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
        ProtectSheets
    End Sub
    Private Sub Workbook_Open()
        USERID = Environ("username")
        If USERID <> "Admin" Then ProtectSheets
        UnprotectSheet
    End Sub
    Private Sub ProtectSheets()
        Sheet1.Protect "password"
        Sheet2.Protect "cadpassword"
        Sheet3.Protect "manpassword"
        Sheet4.Protect "gaypassword"
        Sheet5.Protect "tvcpassword"
        Sheet6.Protect "cdhpassword"
        Sheet7.Protect "grhpassword"
        Sheet8.Protect "tchpassword"
    End Sub
    Private Sub UnprotectSheet()
        If (USERID = "kalton") Or (USERID = "sheater") Or (USERID = "aavery3") Or (USERID = "thughes") Or (USERID = "mbennett6") Then Sheet1.Unprotect "password"
        If (USERID = "aaben2") Or (USERID = "cjurick") Or (USERID = "tkline") Or (USERID = "mbennett6") Then Sheet2.Unprotect "cadpassword"
        If (USERID = "aaben2") Or (USERID = "cjurick") Or (USERID = "tkline") Or (USERID = "mbennett6") Then Sheet3.Unprotect "manpassword"
        If (USERID = "aaben2") Or (USERID = "jshaw6") Or (USERID = "mbennett6") Then Sheet4.Unprotect "gaypassword"
        If (USERID = "aaben2") Or (USERID = "jshaw6") Or (USERID = "mbennett6") Then Sheet5.Unprotect "tvcpassword"
        If (USERID = "aaben2") Or (USERID = "skillingbeck") Then Sheet6.Unprotect "cdhpassword"
        If (USERID = "aaben2") Or (USERID = "skillingbeck") Then Sheet7.Unprotect "grhpassword"
        If (USERID = "aaben2") Or (USERID = "skillingbeck") Then Sheet8.Unprotect "tchpassword"
        
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 01-18-2023 at 02:29 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Protecting a sheet with a password in VBA
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-19-2020, 01:00 PM
  2. Codes to allow or not all users when protecting sheet
    By tigergutt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2016, 02:59 PM
  3. Replies: 12
    Last Post: 10-16-2014, 09:02 AM
  4. [SOLVED] Password Protecting Sheet
    By nickhunt in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-15-2014, 10:00 AM
  5. Protecting sheet password
    By John Cruz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2014, 01:29 AM
  6. [SOLVED] Password Protecting a Hidden Sheet
    By JRose0303 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-25-2014, 12:30 PM
  7. Sheet Protecting password
    By Nick in forum Excel General
    Replies: 1
    Last Post: 06-29-2005, 08:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1