+ Reply to Thread
Results 1 to 4 of 4

Protect Worksheet with Password

  1. #1
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Protect Worksheet with Password

    Hello, could someone please help me modify my code so that the user is prompted with a password inputbox to both protect and unprotect my worksheet named: Data. I am using Excel 2003.

    Thanks,

    Chris

    Please Login or Register  to view this content.
    Last edited by longbow007; 01-22-2010 at 12:55 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Protect Worksheet with Password

    You really want "users" to have to know passwords and then remove them and add them back in? Letting them do that will seriously give them the ability to lock YOU out of their sheet.

    Wouldn't it be better to simply allow your macro to work on the sheet without unprotecting it?

    To do that, put this macro into the ThisWorkbook module:
    Please Login or Register  to view this content.
    Be sure to put in the correct password, the red code is the part that makes the "Data" sheet able to run macros even though it's protected.

    Once the macro is installed, save your sheet, close it, then reopen it, that will set the flag properly.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Protect Worksheet with Password

    Hi JBeaucaire, thank you so very much for your excellent suggestion - very much appreciated. I am experiencing a compile error: Ambiguous name detected: Workbook_Open.

    It may be just me, but I entered your code in ThisWorkbook module and entered the password where you had the word: Password in blue text. I then, saved my workbook and closed it.

    I am not sure why I get this is happening? Do I need to keep my original VBA code the same or do I need to delete all references to both protect and unprotect my worksheet?

    Cheers,

    Chris.

  4. #4
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Protect Worksheet with Password

    Hi JBeaucaire - oops, my bad, I have fixed my problem up - all OK now. Thanks again for your help.

    Cheers,

    Chris.

+ 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