+ Reply to Thread
Results 1 to 9 of 9

Password protection??

  1. #1
    Registered User
    Join Date
    05-12-2008
    Posts
    40

    Password protection??

    I have the macro code below to unprotect a worksheet, then run a function, and then finally re protect the work sheet.
    However i would like to add in a password to be entered when the macro is run, then when the worksheet is re-protected the password is automatically entered.
    e.g. the code would say:
    1. enter password
    2. unprotect worksheet
    3. delete selection
    4. password protect worksheet.


    Please Login or Register  to view this content.

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi arfanvilla,

    You could use an input box, example:

    Please Login or Register  to view this content.
    and then use pwd as the new password string
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try
    Please Login or Register  to view this content.
    Hope that helps.

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

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    05-12-2008
    Posts
    40
    thanks for your reply.

    However, when i try to unprotect the worksheet from the tools->protection option then it does not require a password to unprotect. This is obviously unacceptable as the worksheet needs to remain password protected.

    any ideas to keep the worksheet password protected before and after running the macro.

    thanks

  5. #5
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Your sheet will need to be protected by a standard password of your choice but if the user will then change it and saves the workbook that will be the new password.

    you may want to try hiding what ever the password the user enters somewhere out of the way so you can look it up when unprotecting the worksheet.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The code that I provided allows for the sheet to be protected using inbuilt Protection from the Tools menu, in the example "secret". It then prompts the user for this password, if it is wrong it will not continue.

  7. #7
    Registered User
    Join Date
    05-12-2008
    Posts
    40
    i think you might have misunderstood what i wanted initially. (my fault)
    the main problem is re-protecting the worksheet.

    The code you have given me password protects the macro not the worksheet -> a macro can only run when the password is entered. (this will still come in handy, so thanks again)
    However what i have done is to protect the sheet with password via the tools menu, then i need to run the macro.
    The macro cannot run because the sheet is protected so therefore i need to unprotect the sheet. Now if there was no password this is already done, but with password it becomes more difficult and is where i need help.
    When the ActiveSheet is unprotected the default 'enter password' box appears and the password is entered and macro will run.
    when the sheet is re-protected it is protected without password:

    Please Login or Register  to view this content.
    So therefore the password needs to be re-entered, this is ideally to be done without a message box, so the password is to be entered automatically within the code.
    Again i need help with this part.

    The process so far goes like this:
    1. The worksheet is protected with password via the tools menu options.
    2. The macro is selected to run.
    3. Password is required to run macro: 'secret'
    4. Password is then again required to unprotect the woksheet
    5. macro runs correctly
    6. sheet is protected
    7. when unprotecting the sheet via the tools menu option the worksheet password is not required <- Core Problem.

    thanks again for your replies, hope you have some ideas, thanks.

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

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-12-2008
    Posts
    40
    all it needed was those few extras and it worked, cheers mate

+ 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