Forum Discussion

esatyilmaz's avatar
esatyilmaz
Copper Contributor
Jul 14, 2022
Solved

Excel 365 VBA vs Review>Protect Sheet password

Hello,

 

I am encountering a strange issue. I lock a worksheet by Review>Protect Sheet and set a worksheet password such as 0010 and then in the VBA code I want to unprotect with the same password to run a piece of code. But it generates an error saying password doesn't match. Below is the code I use to unprotect.

 

Application.Worksheets("Example").Unprotect (Password = "0010")

 

Did anyone encounter this strange phenomenon? Any recommendations?

  • esatyilmaz 

    At the beginning of the procedure you can use
    Me.Unprotect("0010")
    or you can use
    ActiveWorkbook.ActiveSheet.Unprotect("0010")
    to use

     

    'Your code

     

    at the end of the procedure
    Me.Protect ("0010")
    or you can
    ActiveWorkbook.ActiveSheet.Protect("0010")
    to use.

     

     

    Hope I could help you with these information 

     

    NikolinoDE

    I know I don't know anything (Socrates)

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    esatyilmaz 

    At the beginning of the procedure you can use
    Me.Unprotect("0010")
    or you can use
    ActiveWorkbook.ActiveSheet.Unprotect("0010")
    to use

     

    'Your code

     

    at the end of the procedure
    Me.Protect ("0010")
    or you can
    ActiveWorkbook.ActiveSheet.Protect("0010")
    to use.

     

     

    Hope I could help you with these information 

     

    NikolinoDE

    I know I don't know anything (Socrates)

Resources