Share a work book base on user name and password

  • Hi I am looking for a code which can guide me to create userform to have a user name and password. Based on the user name and password the user will have access to only a specifc sheets.

  • Re: Share a work book base on user name and password


    You need to have a hidden sheet (called Sheet1 in the macro) with the usernames on and in the column next to it have the sheet name that you want them to view. You also need a sheet called Welcome as this will be the only one displayed if macros are turned off or they don't have sheet access.



    This goes in the Thisworkbook module

  • Re: Share a work book base on user name and password


    Thank simon for your help. In the mean while i have managed to find another thread with an example. I have tried to use this code with my work book but the difference is i have a workbook with 12 sheets and when i try to use this code it says invalid sheet names i am all confused as to why.

    Password are :

    Pass for vba editor: admin


    User Pass
    admin admin
    scott 154
    jack 212
    mark 123

    I am looking to creat something similar but i am just being able to.

  • Re: Share a work book base on user name and password


    When I tried using your file, it all worked just fine, with the exception of username mark. In that case, the list of sheets to unlock had a space after the comma, which the split function in UnlockSheets was not prepared to deal with. If I took out the extraneous space in cell C5, then all the users worked just fine. The way the code is written, it looks like you could also get an invalid sheetname result if you input "Name" and "Password" as the name and password entries, as it would then be attempting to open a non-existent sheet named "Sheets".


    I would also add that if the information you are keeping hidden from some of the users is highly confidential, this is not a particularly secure way of protecting it from them. Even if they don't themselves have the Excel/VBA skills to crack it, they might know someone who does and who would do it for them. I could crack this in a matter of minutes, and have done so in the past with other files I receive where I want to know what's been hidden.

  • Re: Share a work book base on user name and password


    Thanks for your help. Simon do you have another way that this could be well secure. Since i used the code which i had posted earliar. There seems to be a major glitch to it which i just figured out. That when a user opens the file and enters his/her username and password. When they go to their individual file and press Ctrl + s, all the files get unlocked.

  • Re: Share a work book base on user name and password


    As Barb already said, using Excel to hide confidential information on worksheets is never going to be secure.

    This technique is fine as a way to avoid confusing users by hiding information that is not relevant to them. You would need to take an entirely different approach if the information is confidential.

  • Re: Share a work book base on user name and password


    Thanks Rob would there be a possible way to disable to use the Save option in excel but need the file save automatically once closed using the cross button?

  • Re: Share a work book base on user name and password


    Well i asked this because i am using the same code as the excel file attached to this thread only i have changed the names according to my requirement. The reason ask about the save option is because as mentioned before when a user saves the file using the menu buttons, tool bar button or Ctrl +S that unlocks all the files for the user. So if i do not give them the option to save the file working on it they wouldnt be able to unlock the rest and to save the file will only have to close the document. Once they open the document again it is in it original status with all worksheets locked and only can access their document.

    I have one more question which doesnt relate to this but i hope someone can help. Excel suddenly gives me an error saying
    "Path/File access error: '.\VBA2.tmp' " When ever i open any excel document. Ho do i get rid of this issue.

  • Re: Share a work book base on user name and password


    A lot depends on what level of security you are trying to achieve. The issue with Excel passwords and VBA as security is that the workbook can be loaded with macros disabled and then any security that is being imposed by your VBA is nullified. Excel passwords can also be cracked within minutes using VBA.

  • Re: Share a work book base on user name and password


    Is there any code where i could Disable the save, save as button in the menu, Disable the save button on the tool bar , disable the Ctrl + S function for 1 specific workbook ?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!