Consulting

Page 1 of 3 1 2 3 LastLast
Results 1 to 20 of 41

Thread: Solved: Different Passwords for all Users to view W/sheets 1 master password

  1. #1
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location

    Solved: Different Passwords for all Users to view W/sheets 1 master password

    Summary of what I am wanting to achieve:
    Workbook opens on a Sign-In worksheet - user enters their unique password and gets taken to their worksheet - if they navigate away from their worksheet they have to go back to the Sign-In worksheet - when they close the workbook it re-sets to outcome one (Workbook opens on a Sign-In worksheet) - and finally a super password that can enter every worksheet
    The practical use: I am trying to set a regular fortnightly test for my team (15 people) that is simple to use and writes itself. My team members supply one question each and the answer to that question making up a 15 question test.

    On the 15 worksheets (one for each team member) is 15 rows with 3 columns - the rows have the names of each team member in column 1.

    In column 2 they can write their question and in column 3 write the answer to that question.

    They can see the questions already set by the team members who have had earlier shifts than them - but obviously not the answers. I have done this by using (for example) =John!D3 to import the question from John's worksheet to the other team members worksheets.
    I want access to all their worksheets (the second password of each worksheet) so that I can make sure the questions have relevance to our work, the answers they have given are correct and I can, when everybody has set their questions and answered the questions of everybody else, go through and mark them.

    I'll have a results worksheet that shows each team member whether he got the other questions right or wrong and that shows all the questions again with their answers so that, if anybody disagrees with the answer, thinks their answer was better etc., it can become a discussion point to the good of us all (the whole object of this testing system) - our work can be very subjective - hence the possible disagreement about the answers.
    What code I have found: I have spent weeks trolling the net - few codes addressed my need that nobody can even view the worksheets without the correct password and reset the system on closing the workbook.... but, here is one that did (however it doesn't close (re-hide) the worksheet if you navigate away from the worksheet with the workbook still open):

    [VBA]Option Explicit
    Option Compare Text
    'Password to unhide sheets
    Const pWord = "help"

    Sub HideSheets()
    'Set worksheet to Very Hidden so that it can only be unhidden by a macro
    Worksheets("John").Visible = xlSheetVeryHidden
    End Sub

    Sub ShowSheets()
    'Prompt the user for a password and unhide the worksheet if correct
    Select Case InputBox("Please enter the password to unhide the sheet", _
    "Enter Password")

    Case Is = pWord
    With Worksheets("Jon")
    .Visible = xlSheetVisible
    .Activate
    .Range("A1").Select
    End With
    Case Else
    MsgBox "Sorry, that password is incorrect!", _
    vbCritical + vbOKOnly, "You are not authorized!"
    End Select
    End Sub

    Option Explicit

    Private Sub Workbook_Open()
    'Turn off screen updates
    Application.ScreenUpdating = False

    'Hide confidential sheet at startup
    Call HideSheets

    'Activate cell A1 on the Dashboard sheet at startup
    With Worksheets("Sign-In Page")
    .Activate
    .Range("A1").Select
    End With

    'Restore screen updates
    Application.ScreenUpdating = True
    End Sub

    [/VBA]





    I even found one code that had the option of 2 different passwords To view it: (But it was for only one worksheet - not the 15 I need)

    [VBA]Dim LastActiveSheet As Worksheet


    Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    If Not Sh Is Sheets("Sheet4") Then
    Application.ScreenUpdating = False
    Set LastActiveSheet = Sh
    End If
    End Sub


    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Sh Is Sheets("Sheet4") Then
    Sh.Visible = False
    With Application
    .EnableEvents = False
    LastActiveSheet.Activate
    .EnableEvents = True
    End With
    PromptForPassword
    End If
    End Sub


    Sub PromptForPassword()
    Dim UserInput As Variant
    Const PWord1 As String = "Enter Password1 Here"
    Const PWord2 As String = "Enter Password2 Here"
    Const Msg1 As String = "Sheet Locked For Viewing !" & vbNewLine _
    & vbNewLine & "Enter Password To Unlock."
    Const Msg2 As String = "Wrong Password !"

    With Application
    Do
    UserInput = .InputBox(Msg1)
    Select Case UserInput
    Case Is = False ' if user cancells don't activate sheet
    Exit Do
    Case Is = PWord1, PWord2 '**if password correct activate sheet4
    Set LastActiveSheet = Sheets("Sheet4")
    Exit Do
    Case Else 'if wrong password give user another try
    UserDecision = MsgBox(Msg2, vbRetryCancel): Beep
    End Select
    Loop Until UserDecision = vbCancel

    Sheets("Sheet4").Visible = True
    .EnableEvents = False
    LastActiveSheet.Activate
    .EnableEvents = True
    End With
    End Sub


    [/VBA]
    CAN YOU HELP?

    So, I've found some of the elements of what I want to do - I just don't know how to combine them and what I need to add to achieve my final goal - which (to re-iterate) is:
    1. The workbook opens on a sign-in worksheet.
    2. From a menu of names on that sign-in worksheet a unique password takes them To their worksheet.
    3. If they move To another worksheet they have To go back To the sign-in menu To get back To their worksheet.
    4. Each worksheet has 2 password options (theirs And mine which I use To access every worksheet) - alternatively, it might be easier To have a 'super' password icon for me on the sign-in worksheet that turns off all other passwords while I'm working the workbook
    5. When the workbook Is closed it re-sets To 1.



    Thanks for reading this and hopefully see an easy way to cobble the code I've already found to a bit more for me.


    Regards,
    Jon.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Will you know each of the users passwords?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location
    Yes... if for no other reason than I will have to go through the code to put each persons password in.

    The pass wording need is so that everybody can contribute their 1 question - with its answer - to these tests without allowing them to see the answers left by the other team members (or other team members seeing the answer to their question) until all have completed the test and the test with answers gets published by me.

    I'm sure others will be able to adapt the code to do what I want for other useful purposes - e.g. A employee diary that has public (for all to read) items and private (only they can read pages) that the boss (me) can leave messages or instructions that are not for 'everybody's eyes'.

    On re-reading my request I see that the 'super password icon' on the log-in worksheet (that I hoped for) that turns off the passwords so I can jump between worksheets (checking questions, marking answers etc) would have to be pass-worded to stop my staff from turning the passwords off (and thereby allowing them to cheat in the test).

    To stop cheating the code would need to be hidden as some of my people are familiar enough with excel to find and view unprotected code.

  4. #4
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location
    [Only saw I could edit my posts after I had posted this (now erased) post... sorry]

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    You can password protect the project to stop other from "accidentally" editing the workbook code. Just one other question whilst MD is gaining some quality sleep time, is can an employee change or edit a password or do they have to request a new one from you?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location
    Aussiebear (great to see another Banana Bender on this site),

    Yes, giving the option to change their passwords would be great - but, I worry that my 'wish list' is already far too long.

    While I've been exploring this site (which I have discovered has little elements of most of the things I want) I have seen lots of 'extras' that would be nice - one example is a splash display when Users first open the workbook - but, most are things I'd only do to 'pimp' up the workbook (as opposed to adding real value) if I only knew how to properly install them.

    I tried following the explanation of what goes where (this workbook, sheets, this project etc.) but a lot of what I see must assume the reader has a better understanding of VBA than I do (either that or I'm particularly thick).

    A few codes I've used in the past, I've been told, require them to be nested by keying alt this or that (or is it ctrl this or that) with no explanation as to why you just can't copy and paste them.

    Anyway, thanks for your interest... hopefully MD is not too busy to write me something that meets my basic requirements (and it doesn't take too much out of his, no doubt, busy schedule)

  7. #7
    VBAX Contributor
    Joined
    Jul 2004
    Location
    Gurgaon, India
    Posts
    148
    Location
    Hi,

    You could download a sample workbook from here

  8. #8
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location
    Hi Krishna... I downloaded the xls and [as good as it is] it doesn't have the fundamental features I need - password protection for the viewing of each sheet with a different password for all sheets and a master password I can access them all. Thanks anyway for the thought.

  9. #9
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location
    If it helps MD (or anyone else looking to help me) I just found this code that might by quicker to add to, to give me the other features on my wish list:

    [vba]Sub ProtectAllSheetsSamePW()
    Dim wSheet As Worksheet

    For Each wSheet In Worksheets
    wSheet.Protect Password:="secret", UserInterfaceOnly:=True
    Next wSheet

    End Sub

    Sub ProtectAllSheetsNOTSamePW()
    Dim wSheet As Worksheet, strPassword As String

    For Each wSheet In Worksheets
    Select Case UCase(wSheet.CodeName)
    Case "SHEET1": strPassword = "carrot"
    Case "SHEET2": strPassword = "secret"
    'Follow pattern
    Case Else: strPassword = "generic"
    End Select
    wSheet.Protect Password:=strPassword, UserInterfaceOnly:=True
    Next wSheet

    End Sub[/vba]

    I just loaded a workbook with this and it only passwords the sheets - it doesn't stop them being viewed
    Last edited by jbri; 05-26-2009 at 07:23 PM.

  10. #10
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location
    Hi All - I guess everyone's given up? Nevermind, this VBA isn't exactly what I want but, I can use it to get my staff tests underway while I play with it to give me everything I was hoping for [CREDIT FOR THIS VBA GOES TO A VBA REGULAR CALLED Mikerickson WHO ANSWERED (on 1 Mar 09) A PLEA FOR HELP ON 28 Feb BY jiddings ENTITLED 'protecting multi shts with separate pwrds']

    [VBA]Private Sub Workbook_Open()
    Dim uiPassword As String
    Dim oneSheet As Worksheet
    Dim SheetsToSee As String

    With ThisWorkbook
    .Sheets("EveryBodyCanSeeMe").Visible = xlSheetVisible
    For Each oneSheet In .Sheets
    If oneSheet.Name <> "EveryBodyCanSeeMe" Then
    oneSheet.Visible = xlSheetVeryHidden
    End If
    Next oneSheet
    End With

    uiPassword = Application.InputBox("Enter your password", Type:=2)

    Select Case LCase(uiPassword)
    Case Is = "False"
    Exit Sub: Rem cancel pressed
    Case Is = "password1"
    SheetsToSee = "Sheet1 Sheet2"
    Case Is = "password2"
    SheetsToSee = "Sheet1 Sheet3"
    Case Is = "password3"
    SheetsToSee = "Sheet2"
    Case Else
    MsgBox "bad password"
    SheetsToSee = vbNullString
    End Select

    For Each oneSheet In ThisWorkbook.Sheets
    If 0 < InStr(SheetsToSee, oneSheet.Name) Then
    oneSheet.Visible = xlSheetVisible
    End If
    Next oneSheet

    Rem optional hides EveryBodyCanSeeMe If password Is good
    ThisWorkbook.Sheets("EveryBodyCanSeeMe").Visible = IIf(SheetsToSee = vbNullString, xlSheetVisible, xlSheetHidden)

    End Sub
    [/vba]

    Oh - and I'll protect the passwords from being seen if the code is viewed by those who know how to view it by:
    To protect your VB code from being seen by others, all you need to do is go to the project explorer, point at your project and right click on it. Select VBA project properties, click on the protection tab and check the Lock project for viewing and key your password. That's it. [Thanks to 'Julian's Excel Macro (VBA) Tips to Beginners' - found on Gooogle - for this one]

    Gee - seems I'm learning useful stuff everyday

    I am still keen for some kind soul to show me how to add to the above code to do the other things I wanted.
    Last edited by jbri; 05-28-2009 at 10:06 PM.

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Quote Originally Posted by jbri
    Hi All - I guess everyone's given up? Nevermind, this VBA isn't exactly what I want but, I can use it to get my staff tests underway while I play with it to give me everything
    Hmmm.... given up???? That doesn't sound like a Queenslander attitude. jbri, whilst this project is highly important to you, it may not carry the same level with others who frequent this forum. I'm sure you've read posts in forums and passed over them for one reason or another. If you can persevere a little bit, someone will be along to assist you.

    Why not throw up a workbook with what you have so far, and we'll have a quick look?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  12. #12
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Have a look at this for a concept;

    http://groups.google.com/group/micro...3bc6ed71a24179
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  13. #13
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Ooops.. my system is acting strangely.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  14. #14
    VBAX Regular
    Joined
    May 2004
    Location
    Brisbane, Australia
    Posts
    20
    Location
    Aussiebear (or can I call you Koala?) - No I hadn't given up, I just thought everybody else might have) - in fact, that I'm still copying bits of code and finding ways of mating them shows I'm 1. not just sitting back waiting for it to 'drop into my lap' and 2. actually trying to improve my knowledge so I can help others with similar needs.

    Tonight I'm re-writing that last (working) code I found with one that gives multiple password tries before it closes down (which the one I found does).

    I'm anticipating I'll have it cracked tonight or tomorrow and it was then my intention of posting the working version here so others can make use of it.

    Actually I don't think I've ever passed by a post I could be assistance with (but, you'll have to take my word on that), however, with my knowledge of VBA there arn't that many I can help with (heh heh).

    I don't have a workbook worth uploading - the best I've had I had to erase today because the code I loaded into it wouldn't accept the password and kept closing. Having spent quite a bit of time pimping up the one I had to erase, I've learned my lesson so, what I'm doing now is opening new workbooks, trying to get them to work and when they do (like this last one posted does) I'll pimp up that workbook and post it here.

    Not that I wouldn't like a bit of help (with cleaner, smarter ways of doing it), by not getting immediate help it has forced me to self-teach, experiment and get a lot 'VBA smarter' than I would have if my first post had received a complete working model to the specks requested - gee, I might even become an 'expert' on here helping others (heh heh).

    For your (apparent) interest here is how I've modified the above code (which works in the test I did this afternoon at work):

    [VBA]Private Sub Workbook_Open()
    Dim uiPassword As String
    Dim oneSheet As Worksheet
    Dim SheetsToSee As String

    With ThisWorkbook
    .Sheets("Sheet4").Visible = xlSheetVisible
    For Each oneSheet In .Sheets
    If oneSheet.Name <> "Sheet4" Then
    oneSheet.Visible = xlSheetVeryHidden
    End If
    Next oneSheet
    End With

    uiPassword = Application.InputBox("Enter your password to view your worksheet - Once there enter your question for the test, enter your answer to that question, answer any of the other available questions and, finally, do not forget to save before exiting", Type:=2)

    Select Case LCase(uiPassword)
    Case Is = "False"
    Exit Sub: Rem cancel pressed
    Case Is = "a"
    SheetsToSee = "Sheet2"
    Case Is = "b"
    SheetsToSee = "Sheet3"
    Case Is = "c"
    SheetsToSee = "Sheet5"
    Case Else
    MsgBox "bad password"
    SheetsToSee = vbNullString
    End Select

    For Each oneSheet In ThisWorkbook.Sheets
    If 0 < InStr(SheetsToSee, oneSheet.Name) Then
    oneSheet.Visible = xlSheetVisible
    End If
    Next oneSheet

    Rem optional hides EveryBodyCanSeeMe If password Is good
    ThisWorkbook.Sheets("Sheet4").Visible = IIf(SheetsToSee = vbNullString, xlSheetVisible, xlSheetHidden)


    End Sub
    [/VBA]


    Tonight I'm going to try and integrate this following code to give the above code 3 password attempts before closing:


    [VBA]Dim sLast As Object

    Private Sub Workbook_Open()

    'Ensure Sheet1 is not the active sheet upon opening.

    If Sheet1.Name = ActiveSheet.Name Then Sheet2.Select

    End Sub

    Private Sub Workbook_SheetActivate(ByVal Sh As Object)

    Dim strPass As String

    Dim lCount As Long

    If Sh.CodeName <> "Sheet1" Then

    'Set sLast variable to the last active sheet _

    'This is then used to return the user to the _

    'last sheet they were on if password is not known _

    'or they Cancel.

    Set sLast = Sh

    Else

    'Hide Columns

    Sheet1.Columns.Hidden = True

    'Allow 3 attempts at password

    For lCount = 1 To 3

    strPass = InputBox(Prompt:="Password Please", Title:="PASSWORD REQUIRED")

    If strPass = vbNullString Then 'Cancelled

    sLast.Select

    Exit Sub

    ElseIf strPass <> "Secret" Then 'InCorrect password

    MsgBox "Password incorrect", vbCritical, "Ozgrid.com"

    Else 'Correct Password

    Exit For

    End If

    Next lCount


    If lCount = 4 Then 'They use up their 3 attempts

    sLast.Select

    Exit Sub

    Else 'Allow viewing

    Sheet1.Columns.Hidden = False

    End If

    End If

    End Sub
    [/VBA]
    I hope this display of perseverance on my part lives up to your expectations of what spirit a Queenslander should exhibit (I'm coming back to Brisbane on the 11th of June for annual leave if you'd like to share a beer to have a laugh about our exchanges on this site).
    Last edited by jbri; 05-29-2009 at 05:20 AM.

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you put together what you have in a sample workbook I'll have a look.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    I note that the second section of code came from OZGRID website. Did you follow the link that I provided to see if that would be of any use to you?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  17. #17
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  18. #18
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    The attached workbook has the following functions;

    1. User & password protection for 15 users,
    2. Log on msgbox on opening file,
    3. Each User has access to their own sheet + Main Sheet,
    4. On closing their worksheet, the workbook will close down.

    Credit for the code concept goes to Allen Wyatt, all I've done is amend it slightly to your requirements. Others may wish to amend further, and post back to the forum.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  19. #19
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Ted,
    Here is a modified version. For my code I've copied the Names/Passwords to sheet Main, and also show the Questions/Answers. These can be hidden and made visible by entering the Master password.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  20. #20
    VBAX Regular
    Joined
    May 2009
    Posts
    46
    Location
    Hmm,
    with this however, will users be able to modify the others cells in there worksheet, or just the one's for their question and answer?

    im saying this because by changing the question column from b to c, it will show the answer.

Posting Permissions

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