+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 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
    Excel 2016
    Posts
    9,266

    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 Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,860

    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
    Excel 2016
    Posts
    9,266

    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
    Excel 2016
    Posts
    9,266

    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 Poizhan's Avatar
    Join Date
    02-06-2014
    Location
    Jesus is Lord
    MS-Off Ver
    Excel 2013
    Posts
    316

    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 Poizhan; 02-12-2019 at 07:14 PM.
    John 14:6 KJV "Jesus saith unto him, I am the way, the truth, and the life: no man cometh unto the Father, but by me."

  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 Poizhan's Avatar
    Join Date
    02-06-2014
    Location
    Jesus is Lord
    MS-Off Ver
    Excel 2013
    Posts
    316

    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
    UK
    MS-Off Ver
    2010 primarily
    Posts
    3,129

    Re: Help! Password Protection VBA

    I suspect the password was actually TRUE unless you have a variable called Password assigned another value.
    Rory
    Days when we raged, we flew off the page
    Such damage was done

  14. #14
    Valued Forum Contributor Poizhan's Avatar
    Join Date
    02-06-2014
    Location
    Jesus is Lord
    MS-Off Ver
    Excel 2013
    Posts
    316

    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.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

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