VBA allowing Macro on protected worksheet

37 Views Asked by At

Does anyone know if there is a way to allow VBA to run macros on a protected worksheet without writting the password in the code itself?

    Sub UnProtect_Modify_Protect()

  ThisWorkbook.Worksheets("Sheet1").Unprotect Password:="Password"
'Unprotect

  ThisWorkbook.ActiveSheet.Range("A1").FormulaR1C1 = "Changed"
'Modify

  ThisWorkbook.Worksheets("Sheet1").Protect Password:="Password"
'Protect

End Sub

What I am afraid of is the macro running into a bug right after unprotecting the worksheet, this would leave it unprotected indefenitely.

Thanks.

0

There are 0 best solutions below