VB project unprotect


Posted by Jeffro on January 18, 2002 11:03 PM

I find it necessary to lock my VBA project with a password to stop my co-workers from poking around inside the modules. However, one of my macros requires input from the user via an input box & it then changes the contents of another macro. But, it can't do this when the project is locked.
Is there a way for a macro to unlock the project, continue running & then lock it again at the end?
Kind regards,
Jeffro
Australia

Posted by Jack in UK on January 19, 2002 6:29 AM

Hi Jeffro in Australia (hope alls OK on the other side of the world)

I have the same issues and have found staff will only bust anything they can get their hands on so PW protect is the answer - to unlock and lock on the fly via a diff Script will need some cool code - i have never solved this issue, but what i have done before is call another editable macro say call Input: at a given pount and them ahve the editable part there just a few lines of code and re call the original macro and continue so then you have the best of both worlds, and if the staff access the called code it simple and quick to replace, i save all macros to *.bas by export so i can import in a second and repair damage without effort or care,

HTH
Jack in the UK

Posted by Bariloche on January 19, 2002 7:33 AM

Jeffro,

You can also checkout my response to Sue in the thread that is four threads above yours. Unfortunately the answer is basically "No" but I also give some possible avenues of "attack" for this problem (none of which is my original thinking, but checkout my response and you'll see what I mean.)

good luck



Posted by Joseph Was on January 19, 2002 11:04 AM

This will Lock and unlock

Sub myUnLock()
'This code will unprotect the sheet.
Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveSheet.Unprotect ("admin")
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub

Place this code in a module.

Private Sub Worksheet_Change(ByVal Target As Range)
'
' Macro by Joseph S. Was
'
Application.EnableEvents = False

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="admin"
Application.EnableEvents = True
End Sub


Then this code go's in the Sheet module to re-protect after the module UnProtect code has finished. Put your code in the unprotect module. JSW