I am currently working on a VBA-Project where I want to protect the Code with a password.
Furthermore, I want to use the following lines of code:
Public Sub main()
'Dim CodeModuleSoure As Variant
Dim CodeModuleDestination As Variant
With Application.VBE.ActiveVBProject.VBComponents
'Set CodeModuleSoure = Nothing
Set CodeModuleDestination = .Item(.Count)
CodeModuleDestination.codemodule.addfromstring "Private Sub Worksheet_Activate()" _
& vbCrLf & "Call RefreshRibbon" _
& vbCrLf & "End Sub"
End With
End Sub
This basically adds
Private Sub Worksheet_Activate()
Call RefreshRibbon
End Sub
to the code.
As this does not work while the project is still protected I had a "little" research and found this: Is there a way to crack the password on an Excel VBA Project
Lastly I created a function where I first call the "crack" and then the "code-writer":
Sub otherfuncts()
unprotected
Call Sheet4.main
End Sub
When I try to run the otherfuncts function with a Button it gives me this Error:
If I open the VBA-Project it actually is "cracked" and if I rerun the code after viewing the Project the button does not give me an error. Is there a solution that it works in the first try?