Vba lock a sheet with password

Solved
zahr kall Posted messages 63 Status Membre -  
domicol Posted messages 54 Status Membre -
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 réponse

Le Pingou Posted messages 12375 Registration date   Status Contributeur Last intervention   1 476
 
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
zahr kall Posted messages 63 Status Membre 10
 
Awesome!!
Thank you very much, Le Pingou. I didn't think it was that simple!
10
Le Pingou Posted messages 12375 Registration date   Status Contributeur Last intervention   1 476
 
Thank you, you're welcome.
--

Regards.
Jean-Pierre
4