Macro to Protect OK, Unprotect now messed up!
That is because when you record a macro to protect the workbook it does
not automatically record the password. If you go into the vbe your code
will look something like:
Sub Protct()
ActiveWorkbook.Protect Structu=True, Windows:=False
End Sub
change it to:
Sub Protct()
ActiveWorkbook.Protect Structu=True _
, Windows:=False, password:="mypassword"
End Sub
Similarly the macro to unprotect the book should look something like:
Sub Unprtct()
Dim pwd As String
pwd = InputBox("Enter Password...", "Unprotect Book")
If pwd = "mypassword" Then
ActiveWorkbook.Unprotect Password:=pwd
Else
MsgBox "Incorrect Password"
End If
End Sub
And now that you have the password in the VBA code you will probably
want to protect your VBE project so that this can't be viewed. In the
VBE use the menus to goto ToolsVBAProject PropertiesProtection. Check
lock projet for viewing and supply a password.
Hope this helps
Rowan
Stilla wrote:
I thought I was being clever in recording a macro to protect workbooks with a
password, and then another to unprotect, using ctrl+ a diff letter everytime.
OK, it works, but now to unprotect I'm not even being asked for password!!
This happens whether I use the macro or the "unprotect" feature from the
menu. As soon as I choose "unprotect" - VOILA! the sheet is unprotected!
Obviously, it sort of defeats the purpose of protecting in the first place,
if anyone can unprotect.
Is this happening, because I'm doing it on the same PC where my macro is
stored?
Help..
Thanks
|