Linked Questions

Popular Questions

Macro to run when file is protected

Asked by At

I did macro that creates a graph but need to make the file password protected.

Of course, when I protect the file, the macro will stop working.

I inserted the below into my code to unprotect the file, run the code, then protect the file again. As I the code is a function, I had to create two sub procedures, which is maybe the reason why the trick is not functioning.

Any idea how I can fix this?

Option Explicit
Sub protection()

    Worksheets("Sheet1").Unprotect "abc123"

End Sub

Function (here is my function code)

End Function

Sub protection2()
Worksheets("Sheet1").protect "abc123"

End Sub

Related Questions