+ Reply to Thread
Results 1 to 16 of 16

Help! Password Protection VBA

  1. #1
    Registered User
    Join Date
    01-11-2019
    Location
    CHI
    MS-Off Ver
    2013
    Posts
    22

    Help! Password Protection VBA

    Hi! I initially protected a sheet with a blank password. I used incorrect syntax in my code, and now my sheet is locked and I'm unable to unprotect it!

    I tried a few variations of what the password may be, but am unsuccessful. Any idea?

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    01-11-2019
    Location
    CHI
    MS-Off Ver
    2013
    Posts
    22

    Re: Help! Password Protection VBA

    I beat you guys to it!

    Instead of trying to manually unprotect the sheet by entering a password, I dropped the following code into the Exhibit sheet. Worked!

    Please Login or Register  to view this content.
    Last edited by wannaBactuary; 02-12-2019 at 12:25 PM.

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

    Re: Help! Password Protection VBA

    Good to know, but for future reference, we cannot entertain a question about by-passing an Excel worksheet protection issue.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    HTH
    Regards, Jeff

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Help! Password Protection VBA

    Good afternoon wannaBactuary

    We cannot assist in unprotecting a protected workbook - even if it's been protected in error.

    However, if you provide the code you used to protect, then maybe we can reverse the effect? Not promising anything, but it's worth a shot.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  5. #5
    Registered User
    Join Date
    01-11-2019
    Location
    CHI
    MS-Off Ver
    2013
    Posts
    22

    Re: Help! Password Protection VBA

    Got it, thanks! I learned a lesson today on the importance of syntax.

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

    Re: Help! Password Protection VBA

    And how powerful VBA can be if your not sure what was applied.

  7. #7
    Registered User
    Join Date
    01-11-2019
    Location
    CHI
    MS-Off Ver
    2013
    Posts
    22

    Re: Help! Password Protection VBA

    Indeed, and I'm still curious what the password was set to. Any idea what it was based on the code provided?
    Please Login or Register  to view this content.
    edit: I tried things like Password = "", = "", etc.

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

    Re: Help! Password Protection VBA

    I have no idea what the password was set to, but what you show normally means nothing, but the correct way should be...

    Please Login or Register  to view this content.
    Running this bit of code, I now go to the Review tab on the Ribbon >> Protect >> Unprotect Sheet and the sheet opens without a password.

  9. #9
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Help! Password Protection VBA

    I think I might know what is going

    When VBA is evaluating this statement, because you are stating Password = "" and not Password:="", it is not actually passing the string value as a parameter to the .Protect method,

    VBA is evaluating the statement as Sheets("Exhibit").Protect FALSE, because Password = "" is being evaluated as a boolean operation, VBA thinks you're wanting to evaluate Password as a variable of variant type (which has a null value) against a "" value, and returning the value of boolean FALSE to the .Protect method.

    If you were to run this code, and then try to unlock the sheet by typing in FALSE it should unlock
    Last edited by 1aaaaaaaaaaaaaaa; 02-12-2019 at 07:14 PM.

  10. #10
    Registered User
    Join Date
    01-11-2019
    Location
    CHI
    MS-Off Ver
    2013
    Posts
    22

    Re: Help! Password Protection VBA

    Thank you for the suggestion! This makes total sense. I was still curious so I tested it, but didn't seem to unprotect the sheet successfully ;/

  11. #11
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Help! Password Protection VBA

    As a demo- try this code in VBA

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    01-11-2019
    Location
    CHI
    MS-Off Ver
    2013
    Posts
    22

    Re: Help! Password Protection VBA

    Now this definitely works, thanks!

    Well, I guess if you protect using VBA you better be able to unprotect using VBA.
    Last edited by wannaBactuary; 02-12-2019 at 08:50 PM.

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Help! Password Protection VBA

    I suspect the password was actually TRUE unless you have a variable called Password assigned another value.
    Rory

  14. #14
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Help! Password Protection VBA

    @rorya, I think FALSE because NULL (object not set) is not equal to "" (empty string value)

  15. #15
    Registered User
    Join Date
    01-11-2019
    Location
    CHI
    MS-Off Ver
    2013
    Posts
    22

    Re: Help! Password Protection VBA

    Thanks, rorya, you are right! I'll be able to get some sleep tonight.

    Poizhan, thanks again for the explanation.

  16. #16
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Help! Password Protection VBA

    Quote Originally Posted by Poizhan View Post
    @rorya, I think FALSE because NULL (object not set) is not equal to "" (empty string value)
    Try it in the immediate window:

    Please Login or Register  to view this content.
    I'll be very surprised if it doesn't return True. Undeclared variables are Variants, which default to Empty, not Null, and that will let coerce to "" in the comparison.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 13
    Last Post: 04-05-2017, 10:20 AM
  2. Password protection not showing password on screen as user types it
    By tony7262 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2016, 10:05 AM
  3. [SOLVED] VBA Password Protection
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-26-2015, 08:21 AM
  4. [SOLVED] Password Protection Formula - Remembering I already entered the Password!
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-10-2014, 01:35 PM
  5. Password Protection not accepting password
    By Rob K in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 06-20-2014, 07:00 AM
  6. password protection-is there anyway to put a password on running a macro in excel?
    By Solarissf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2008, 10:06 AM
  7. [SOLVED] Password Protection
    By carter in forum Excel General
    Replies: 2
    Last Post: 02-22-2005, 06:06 PM

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