[Excel] allow macro in protected sheet

Hello,
Desperate

How can I enable the use of macros in a protected sheet in EXCEL????

Thank you in advance.

1 answer

  1. Execute a macro on a protected sheet

    You have just protected a sheet in your workbook with a password, but you would like to run a macro on this sheet. Unfortunately, the macro refuses to work and returns an error message.

    To be able to run a macro on a protected sheet, you need to add an instruction that removes the protection before acting on the sheet and another that restores the protection at the end of the procedure.

    Sub MacrowithProtectedSheet()

    ActiveSheet.Unprotect "thepassword"

    'Place your instructions here

    ActiveSheet.Protect "thepassword", True, True, True

    End Sub

    Replace "thepassword" with your password that protects the sheet.
    57
    1. A thousand thanks for this very useful advice,
      Best regards,
      Gael
      0
    2. Hi,
      Very interesting, but should this command be placed at the very beginning and therefore the end of the entire Visual B sheet or at the beginning and end of each macro?
      0
    3. Good evening,
      I have a similar problem: once my Excel sheet is protected with a password, I can't click on a button (userform) without getting an error message asking me to debug!!! Do you have any advice to give me? Thank you.
      William
      0
    4. Apparently yes, it needs to be copied at the beginning of each macro =S
      0
    5. The solution from Yverchu works.
      Thanks to him/her.
      0