Vba lock a sheet with password

Solved
zahr kall Posted messages 63 Status Member -  
domicol Posted messages 54 Status Member -
Hello,
I want to lock my Excel sheet. So I'm using

ActiveSheet.Unprotect
then
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

between the applied macros.
However, when the sheet is locked and someone tries to write on it, a message appears indicating how to unlock the sheet.

I would like to know if there is a similar formula that allows the use of a password or if there is a way to hide the information provided by Windows Excel regarding unlocking the sheet.

I hope I have been clear and thank you in advance for your invaluable help!!!

1 answer

  1. Le Pingou Posted messages 12275 Registration date   Status Contributor Last intervention   1 477
     
    Hello,
    As follows:

    Protection with password ("monmot2passe")
    ActiveSheet.Protect Password:="monmot2passe", DrawingObjects:=True, Contents:=True, Scenarios:=True

    Remove the protection;
    ActiveSheet.Unprotect ("pingoujpp")
    --

    Regards.
    Jean-Pierre
    36
    1. zahr kall Posted messages 63 Status Member 10
       
      Awesome!!
      Thank you very much, Le Pingou. I didn't think it was that simple!
      10
    2. Le Pingou Posted messages 12275 Registration date   Status Contributor Last intervention   1 477
       
      Thank you, you're welcome.
      --

      Regards.
      Jean-Pierre
      4