+ Reply to Thread
Results 1 to 9 of 9

access to worksheet protected by different passwords

  1. #1
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Talking access to worksheet protected by different passwords

    Hello Happy Campers.

    Having recently stumbled across a large code on the old webby for passwrod protecting a work sheet, and then allowing different passwords to be able to unlock different cells, i am trying to put this into practice, and am stuck.
    Please Login or Register  to view this content.
    Is there anyone who has enough time to actually action this into a sheet for me? i have tried but cannot get it right, i would like to get it working to adapt it to suit what im after.
    Would be exceptionally gratefull if you can lend some expertise on this!
    galvingpaddy
    Last edited by galvinpaddy; 11-21-2011 at 06:40 PM. Reason: updated

  2. #2
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: access to worksheet protected by different passwords

    Here is a simple way to have different passwords for different ranges, and then also have a master password. It uses the in-built "Allows Users to Edit Ranges" feature.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: access to worksheet protected by different passwords

    Wow, thanks alot, next question, how do i put that into VBA - Module? Sheet1? what needs to go at the start and end of the code?
    Thanks muchly!
    galvinpaddy

  4. #4
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: access to worksheet protected by different passwords

    You can set this manually, if you want.

    1: Go to the Review tab
    2: Select "Allow Users to Edit Ranges"
    3: Click "New"
    4: Set Name, Range, and Password as desired.
    5: Repeat Password to verify
    6: Repeat steps 3 - 5 as needed.
    7: Click "Protect Worksheet"
    8: Supply password (Note, this password is a "master" password and will unlock all cells in the sheet)
    9: Repeat password to verify.

    This will lock the sheet and allow different ranges to be accessed with different passwords.

    To remove the lock, simply go to the Review tab and click "Unprotect Sheet", then supply the master password.

    To edit the ranges/passwords, unlock the sheet as directly above, then click "Allow User to Edit Ranges" and modify to suit.

    To do all the above programatically, paste the following code into a regular module and edit to suit:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: access to worksheet protected by different passwords

    Fantastic fella,
    Thanks so much!!! Well deserved Rep added :D

  6. #6
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: access to worksheet protected by different passwords

    Here is an updated script. This allows for changes to existing AllowEditRanges.

    Please Login or Register  to view this content.
    Last edited by Whizbang; 11-22-2011 at 04:26 PM.

  7. #7
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: access to worksheet protected by different passwords

    Nice one thanks fella, that code will ehlp for another sheet (shared between areas)

    Stuff of legends mate, cheers!
    galvinpaddy

  8. #8
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Unhappy Re: access to worksheet protected by different passwords

    Hi Fella,
    Apologies for more questions, the below code works great, however, i would like to set the sheet as 'Share Workbook & Allow changes by more than one user at the same time'.
    I have 2 cmd buttons on the sheet, one that will basically activate the below code (so re-locking all unlocked cells, with 'Activeworkbook.SAVE added) and the second is a 'UserAns' box, that asks for the MasterPassword (Lianne) to enable the sheet to be modified fully.
    When i share the workbook, everything works fine, until i click on the cmd button to activate the code, then i receive an error that simply says "400" with the big red X next to it.
    Any ideas??


    Sub LockCellsLive()

    ActiveWorkbook.SAVE
    Dim ProtectionArray(1, 3)
    Dim aer As AllowEditRange
    Dim x As Integer

    ActiveSheet.Unprotect Password:="Lianne" 'Supply current password. If this macro has already been run, then enter the Master Password below

    ProtectionArray(1, 1) = "Range1" 'Name
    ProtectionArray(1, 2) = "(J:J,K:K,O:O,P:P,Q:Q,R:R)" 'Address
    ProtectionArray(1, 3) = "Test" 'Password


    For Each aer In ActiveSheet.Protection.AllowEditRanges
    aer.Delete
    Next aer

    For x = 1 To UBound(ProtectionArray)
    With ActiveSheet.Protection
    .AllowEditRanges.Add Title:=ProtectionArray(x, 1), Range:=Range(ProtectionArray(x, 2)), Password:=ProtectionArray(x, 3)
    End With
    Next x
    ActiveSheet.Protect Password:="Lianne", DrawingObjects:=True, Contents:=True, Scenarios:=True 'Password is the Master Password to unlock all cells.

    End Sub

  9. #9
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: access to worksheet protected by different passwords

    You cannot protect or unprotect a sheet while the workbook is shared. The sharing would need to be removed for the brief time it takes to modify the protection.

    You can either do this manually or through code. Manually will allow you to check if any users currently have the workbook open.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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