+ Reply to Thread
Results 1 to 13 of 13

Excel 2007 : Help with macro for password

  1. #1
    Registered User
    Join Date
    12-31-2010
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    5

    Help with macro for password

    Hi everyone, i'd like your help to solve a problem i have.

    I am no programmer but for work i need to set up an excel file with 4 sheets;

    1-the first sheet must be protected with password and visible ONLY for who has the password.
    2-opening the excel file the user (whoever he is) must see the sheet 2 as first sheet.
    3-when the user clicks on the sheet 1 he can see an empty page (hidden all columns). He needs then to enter the password: if the password is correct the sheet 1 will appear properly, if not, it will stay locked with all columns hidden and no chance to modify it.
    4 and main problem- i want to put the password once and never again until the excel file stays open. I had a macro that did the first 3 steps but i lost it and i had to re.enter the password every time i clicked on "sheet 1", which i don't want to do.
    5-many people use this excel file, i need to hide the macro with the password for the sheet 1.

    I work in an office, my job is not about solving this problem, i'm just an accountancy man, that's why i would really appreciate your help.

    thanks!

    edit: easier solution you could give me:
    i need this behaviour:
    i open the excel file and i can see sheet 2, 3 and 4, while sheet 1 is very hidden (or how you say it, i mean you can't even see it). I need a button on sheet 2 that if i press it i will need to enter a password. If the password is correct sheet 1 will be visible (and editable) until i close the excel file. After that i need to hide the VBA code for the button so that nobody can see what's the password behind it.
    I think it's really easy for you, this second way.
    Last edited by d3stroyah; 01-03-2011 at 03:57 PM.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Help with macro for password

    Ciao 3stroyah,

    Welcome to the Board,

    Here is a start. In a regular module add this macro and then on Sheet2 add your button.

    Please Login or Register  to view this content.
    In the ThisWorkbook module add

    Please Login or Register  to view this content.
    Set the password for Sheet1, but as you see I have entered a password in the code already.

    So nobody will know your password you can protect the VBA.

    In the VBE >> Tools >> VBAProjectProperties >> Protection Tab

    See how this works and then we can refine from here if needed.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    12-31-2010
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help with macro for password

    thanks a lot, it works exactly how expected.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Help with macro for password

    You are very welcome

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help with macro for password

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    12-31-2010
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help with macro for password

    i'm taking up the thread one more time. The solution you gave me is great, but they asked me if there's a way to show a "list of very hidden sheets" pressing the button, and then being able to choose which sheets i want to enable (password is the same for everything).

    So, supposing i have 3 "private sheets" i'd like pressing the botton to have a list where i can chose to enable sheet1, 2, 3, or all of them, and then insert the password. Is that possible (maybe into an input box? I don't know, i'm just guessing)?

    thanks!
    Last edited by d3stroyah; 01-03-2011 at 08:02 AM.

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Help with macro for password

    This sounds possible and I will work something up as soon as I get a chance.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help with macro for password

    You need a userform with a ListBox to list the sheets. This example provides a list to start with.


    SheetsToPrint.zip


    Adapt the code that works on the selected sheets

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help with macro for password

    You need a userform with a ListBox to list the sheets. This example provides a list to start with.


    SheetsToPrint.zip


    Adapt the code that works on the selected sheets

  10. #10
    Registered User
    Join Date
    12-31-2010
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help with macro for password

    haha you guys rock.

    I took the example file and i adapted the code to hide/unhide sheets.

    This is the working file for whoever could need it.

    http://www.megaupload.com/?d=5TRPEJS1

    now i can put [solved]!

    thanks everyone!

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Help with macro for password

    Just wanted to pass along another example.

    Glad you got it working.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    12-31-2010
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Help with macro for password

    wow, that's efficiency . You must be someone really skilled and into it

  13. #13
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Help with macro for password

    Well the skilled part I am far from

    I have just watched very intently here on this forum and others, but ultimately I am starting to understand how to modify some code here or there. Every once in awhile I get lucky.

    Don't ask me to write anything from scatch because there are not enough hours in the day .

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 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